0
我有以下查询:LINQ的分组失去孩子的实体
var _customers = (from c in _db.UserProfiles.Include(x=>x.ParentCompanies).Include(x=>x.cProfile).Include(x=>x.cProfile.PhoneNumbers).Include(x=>x.cProfile.Addresses)
where (c.ParentCompanies.Any(pc => pc.CompanyUsers.Any(cu => cu.UserName == userName)) && c.cProfile != null)
group c by c.FirstName.Substring(0, 1).ToUpper() into customerGroup
select new ContactsViewModel
{
FirstLetter = customerGroup.Key,
Customers = customerGroup
}).OrderBy(letter => letter.FirstLetter);
,如果我拿出group
,它运作良好,并包括所有的孩子(parentCompanies, cProfile, ...)
只要我把group
早在它失去一切的孩子。我该如何解决这个问题?
更新
我想我也应该包括我usign把结果视图模型。
public class ContactsViewModel
{
public string FirstLetter { get; set; }
public IEnumerable<UserProfile> Customers { get; set; }
}
也许http://stackoverflow.com/questions/5343536/linq-ef-eager-loading-and-group-by-issues将帮助你 – 2013-03-26 18:40:27