假设我有实体
Person
------
List<Person> Children
List<Item> FaveBooks
List<Item> FaveSweets
如果我想为一个人加载儿童,这很好。
dataContext.People.Where(x => x.id == personId)
.Include(x.Children).First()
如果我还想要包含儿童FaveBooks,那么简单
dataContext.People.Where(x => x.id == personId)
.Include(x.Children.Select(c => c.FaveBooks)).First()
如何包含儿童的FaveSweets?
dataContext.People.Where(x => x.id == personId)
.Include(x.Children.Select(c => new { c.FaveBooks, c.FaveSweets })).First()
上述内容不起作用,因为我得到The Include path expression must refer to a navigation property defined on the type.
答案 0 :(得分:0)
尝试这样的事情。
dataContext.People.Where(x => x.id == personId).Include(x => x.Children.Select(c => c.FaveBooks)).Include(x => x.Children.Select(c => c.FaveSweets)).First();