如何在包含派生类(EF7-beta8)的<base-class>列表中包含和ThenInclude?

时间:2015-11-09 09:30:26

标签: c# asp.net-core entity-framework-core

假设您有一个包含某个基类列表的类,并且您希望包含在派生类上定义的内容:

public class Cart {
  public List<Product> Products {get;set;}
}

public class Product {
  public string Name {get;set}
}

public class DeliveryProduct : Product {
  public Address DeliveryAddress {get;set;}
}

public class SomeOtherProduct : Product {
  public SomeOtherClass Something {get;set;}
}

我不能简单地做 productContext.Cart.Include(c =&gt; c.Products).ThenInclude(p =&gt; p.DeliveryProduct) 因为有基础型产品上没有DeliveryProduct。

0 个答案:

没有答案