我有一個兩級嵌套的子集合,我投影到DTO中。我的問題也適用於常規父 - >兒童的關係:EF Linq嵌套集合的投影 - 建立關係
// There are two types on Parent and two types of Child classes,
// one is EF model, and another is DTO (here I show only one, for simplicity)
public class Parent
{
public int Id {get;set;}
public IEnumerable<Child> Children {get;set;}
}
public class Child
{
public int Id {get;set;}
public Parent Parent {get;set;}
}
var list = context.Set<Parent>().Select(p=> new DTO.Parent
{
Id = p.Id
Children = (p.Children.Select(c=> new DTO.Child
{
Id=c.Id,
Parent = ?
}))
});
是否有可能分配一個父引用子對象,而這樣做的投影?
當然,這不是目的嗎? 'Parent = p.Id' – 2013-03-11 14:49:23
@BeratBilgin我不明白你到底在說什麼...... – Goran 2013-03-11 16:43:09