Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架:包括继承的类导航属性_C#_.net_Entity Framework - Fatal编程技术网

C# 实体框架:包括继承的类导航属性

C# 实体框架:包括继承的类导航属性,c#,.net,entity-framework,C#,.net,Entity Framework,我的班级结构如下: public class Person { public long Id { get; set; } } public class MarketUser : Person { public ICollection<Order> Orders { get; set; } } public class AdminUser : Person { public ICollection<Request> Requests { get;

我的班级结构如下:

public class Person
{
    public long Id { get; set; }
}

public class MarketUser : Person
{
    public ICollection<Order> Orders { get; set; }
}

public class AdminUser : Person
{
    public ICollection<Request> Requests { get; set; }
}
公共类人物
{
公共长Id{get;set;}
}
公共类MarketUser:Person
{
公共ICollection命令{get;set;}
}
公共类AdminUser:Person
{
公共ICollection请求{get;set;}
}
和一般方法:

public ICollection<TPerson> GetPersons<TPerson>() where TPerson : Person
{
    DbSet personDbSet = GetDbSet<Person>();

    ICollection<TPerson> personsCollection = personDbSet.OfType<TPerson>()
                                                        .Include("Orders")
                                                        .Include("Requests")
                                                        .ToList();

    return personsCollection;
}
public ICollection GetPersons(),其中TPerson:Person
{
DbSet personDbSet=GetDbSet();
ICollection personCollection=personDbSet.OfType()
.包括(“订单”)
.包括(“请求”)
.ToList();
返回人员收集;
}
我正试着这样使用它

ICollection<Person> persons = GetPersons<Person>();
ICollection persons=GetPersons();

问题是,如何加载派生类的导航属性?在本例中,我有一个例外,因为
MarketUser
没有属性
请求
AdminUser
没有属性
订单

,没错,MarketUser没有属性请求,只有订单和Id属性可供MarketUser使用。要正确使用,请将订单和请求移动到Person。或者创建一个特定的GetMarketUser和GetAdminUsers没错,MarketUser没有属性请求,只有Orders和Id属性可供MarketUser使用。要正确使用,请将订单和请求移动到Person。或者创建特定的GetMarketUser和GetAdminUser