我有以下类结构:
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; }
}
和通用方法:
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;
}
我试图像这样使用它
ICollection<Person> persons = GetPersons<Person>();
问题是,如何加载派生类的导航属性?在这种情况下,我有异常,因为MarketUser
没有属性Requests
,而AdminUser
没有属性Orders