我有两个使用外键不相关的表但应该可以连接。关系(不是FK)是一对多的。例如:
Parent <- 1-to-many -> Child
parent
,同时通过某种操作手动设置children
属性样品:
using(var context = new Test.Models.Ef.Entities())
{
var products = from p in context.Parent
join c in context.Child on p.key equals c.parentkey
select new {Parent = p, Child = c};
}
问题:
select p => p.Children = select c group by p
答案 0 :(得分:1)
var products = from p in context.Parent
join c in context.Child on p.key equals c.parentkey
into pc select new { p, pc }
执行GroupJoin,转换为外连接。