我有以下作为我的实体框架类的一部分: -
public CustomerDetails GetCustomer(int id) {
var customerDetails = entities.AccountDefinitions
.Where(a => a.ORG_ID == id)
.Select(cd => new CustomerDetails
{
AD = cd,
SD = cd.SDOrganization,
AA = cd.SDOrganization.AaaPostalAddresses,
SN = cd.SiteDefinitions,
Ar = cd.SiteDefinitions.SelectMany(a => a.DepartmentDefinitions.SelectMany(a2 => a2.SDUsers.Select(a3 => a3.AaaUser)))
})
.SingleOrDefault();
return customerDetails;
}
在内部 .Select 我有五个分配操作,但是由于某些分配依赖于另一个分配,所以我如何编写如下内容:-
Ar = SN.SelectMany(…….)
所以这样我只会查询一次数据库来检索 cd.SiteDefenitions??