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