给定2个具有一对多关系的表,我想执行以下操作,将父ID和子项的名称作为每个父项的嵌套列表:
from p in parent
join c in child on p.ID equals c.ParentID
into parentsChildren
select new {p.ID, parentsChildren.FirstName}
第一个例子没有编译。我知道我可以使用以下SelectMany查询获得相同的结果,但是想要从上面找出等效的GroupJoin语法。
from p in parent
let parentsChildren = from c in p.children
select c.FirstName
select new{p.ID, parentsChildren}
答案 0 :(得分:1)
试试这个
from p in parent
join c in child on p.ID equals c.ParentID
into parentsChildren
select new
{
p.ID,
ChildNames = parentsChildren.Select(c => c.FirstName)
}