我有以下课程:
public class A
{
public int Id {get;set;}
public string Name {get; set;}
public ICollection<B> Bs {get; set;}
}
public class B
{
public int Id {get;set;}
public string Name {get; set;}
public ICollection<C> Cs {get; set;}
}
public class C
{
public int Id {get;set;}
public string Name {get; set;}
}
这些ViewModels
:
public class AViewModel
{
public int Id {get;set;}
public string Name {get; set;}
public ICollection<BViewModel> BViewModels {get; set;}
}
public class BViewModel
{
public string Name {get; set;}
public ICollection<CViewModel> CViewModels {get; set;}
}
public class CViewModel
{
public string Name {get; set;}
}
我想编写一个linq to entity
查询( )来通过它的结果是一个带有s列表的对象Fluent API
来查找一个对象,并且每个都包括一个列表 ,我写了以下查询,但它有一些错误:A
Id
AViewModel
BViewModel
BViewModel
CViewModels
_uow.Repository<A>()
.All()
.Include("Bs")
.Include("Bs.Cs")
.Select(a => new AViewModel
{
Name = a.Name,
Id = a.Id,
(ICollection<BViewModel>)
a.Bs
.SelectMany(
t => a.Bs
.Select(r => new BViewModel()
{
Name = r.Name
Cs =
(ICollection<CViewModel>)
t.Cs.SelectMany(y => new CViewModel()
{
Name = y.Name
})
}
)
)
}
).FirstOrDefault(a => a.Id == 5);
我怎样才能做到这一点?