我有一个两级嵌套的子集合,我投影到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