親子関係(1:n)のテーブルを含むselectステートメントを使用してカスタムエンティティを作成しようとしています。選択したオブジェクトをグループ化しようとしましたが、解決策を見つけるのに問題があります。
私のデータは次の形式になります。
ParentTable
Userid | Col1 | Col2 | ... | Coln
ChildTable:
Id | Userid | Col1 | Col2 | ... | Coln
私が作成しようとしている結果オブジェクトは次のようになります。
Custom { UserID, IEnumerable<ChildTable> }
私はクエリを書きました:
from parent in db.ParentTable
join child in db.ChildTable on new { Userid = parent.Id } equals new { Userid = child.Userid } into child_join
from child in child_join.DefaultIfEmpty()
where
child.Col1 == Argument1 &&
child.Col2 == Argument2
select new {
Username = parent.Username,
child.Col1,
child.Col2,
child.Col3,
child.Coln
}
これにより、次の結果が返されます。
Username | Child Col1 | Child Col2 | Child Col3 | .. |Child Coln
asdf 1 11 22 .. 33
asdf 2 22 33 .. 44
asdf 3 33 44 .. 55
qwer 4 44 55 .. 66
qwer 5 55 66 .. 77
qwer 6 66 77 .. 88
zxcv 7 77 88 .. 99
zxcv 8 88 99 .. 00
私はこれを達成したいと思います:
Username | IEnumerable<Child>
asdf | {{1 11 22 .. 33}
| {2 22 33 .. 44}
| {3 33 44 .. 55}}
qwer | {{4 44 55 .. 66}
| {5 55 66 .. 77}
| {6 66 77 .. 88}}
zxcv | {{7 77 88 .. 99}
{8 88 99 .. 00}}
ユーザー名でアイテムをグループ化し、Custom {UserID、IEnumerable}の形式でカスタムオブジェクトを作成しようとしています。このオブジェクトは、完了したらシリアル化できます。どんな助けでも大歓迎です。編集:データ構造に関しては、サードパーティのシステムに接続しているため変更できないため、与えられたもので作業しています。