15

如果我有以下班级模型......

public class A
{
    public int AId { get; set; }
    public ICollection<B> BCollection { get; set; }
}

public class B
{
    public int BId { get; set; }
    public ICollection<C> CCollection { get; set; }
}

public class C
{
    public int CId { get; set; }
}

...是否可以A从包含所有级联集合的数据库中急切加载类型的对象?

我可以包括BCollection这样的:

A a = context.ASet.Where(x => x.AId == 1)
          .Include(x => x.BCollection)
          .FirstOrDefault();

我是否还可以以某种方式包含CCollection所有加载的B对象,以便A通过单个数据库查询获得内存中的所有依赖对象?

4

1 回答 1

22

使用.Include(x => x.BCollection.Select(b => b.CCollection))描述在这里

它也适用于级联。每次您需要急切加载导航属性时,它就是集合使用.Select

于 2011-03-21T13:46:22.777 回答