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' –
@BeratBilgin 정확하게 말한 것을 이해하지 못합니다 ... – Goran