假设您有一个包含某个基类列表的类,并且您希望包含在派生类上定义的内容:
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。