问题描述
使用EF代码首先给出包含列表的实体,我如何热切地加载该实体的整个对象图:
示例:
public class Foo
{
public int Id {get;组; }
public List< BarBase>酒吧{get;组; }
}
public class BarBase
{
public int Id {get;组; }
public string Text {get;组; }
}
public class BarTypeA:BarBase
{
public List< Baz>巴兹{get;组; }
}
public class BarTypeB:BarBase
{
public List&Quick> Quuces {get;组; } {get;组;
}
如果 BarBase
不是一个可以包含几个不同子类型的基类的基类,我可以使用
.Include(Bars)。 (Bars.Bazes)
如果我尝试
.Include(BarBase)。Include(BarBase.Bazes)。Include(BarBase.Quuces)
/ pre>
我收到错误
但是如何处理
Bars
的情况可以包含不同的具体类型,我想热切地加载所有这些实例,包括List< T>
包含在这些具体类型中?解决方案这是在EF中没有解决方案。
Using EF Code First and given an Entity that contains a List, how can I eagerly load the entire object graph for that entity:
Example:
public class Foo { public int Id { get; set; } public List<BarBase> Bars { get; set; } } public class BarBase { public int Id { get; set; } public string Text { get; set; } } public class BarTypeA : BarBase { public List<Baz> Bazes { get; set; } } public class BarTypeB : BarBase { public List<Quux> Quuces { get; set; } { get; set; } }
If
BarBase
were not a base class that could contain instances of several different subtypes, I could use.Include("Bars").Include("Bars.Bazes")
If I try
.Include("BarBase").Include("BarBase.Bazes").Include("BarBase.Quuces")
I get the error
But how do I handle the situation that
Bars
can contain different concrete types, and I want to eagerly load all of those instances including theList<T>
contained in those concrete types?解决方案This is reported problem in EF currently without a solution.
这篇关于急于加载列表的导航属性< OfSomeBaseClass>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!