我需要将EF实体映射到各自的DTO。在下面的例子中,我有EF实体Parent和Child,而Child实体包含对Parent对象的引用。我也有ParentDto和ChildDto(DTO),而ChildDto包含对ParentDto(不是Parent)的引用。所以,我怎么能在下面的方法分配ParentDto参考ChildDto例如:Linq投影:获取新投影实体的参考
public Task<List<ParentDto>> Method()
{
return (Context.Set<Parent>()
.Where(someCondition)
.Select(p => new ParentDto
{
// here we map all properties from Parent to ParentDto
... ,
Children = p.Children.Select(c => new ChildDto
{
// here we map all properties from Child to ChildDto
... ,
Parent = ? // reference to newly created ParentDto instance
})
}).ToListAsync();
}