Eagerly Load Navigation Property that is List<OfSomeBaseClass>

不想你离开。 提交于 2019-12-19 10:26:32

问题


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

A specified Include path is not valid. The EntityType 'BarBase' does not declare a navigation property with the name 'Bazes'.

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 the List<T> contained in those concrete types?


回答1:


This is reported problem in EF currently without a solution.



来源:https://stackoverflow.com/questions/10342709/eagerly-load-navigation-property-that-is-listofsomebaseclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!