使用实体框架开发基于 TPH 的实体的最佳方法是什么,例如,如果我在广告网站中有公共字段和特定字段:
public class Ad
{
// Primary properties
public int Id { get; set; }
public string Title { get; set; }
public string TitleStandard { get; set; }
public string Version { get; set; }
public string VersionStandard { get; set; }
public int Year { get; set; }
public decimal Price { get; set; }
// Navigation properties
public Color Color { get; set; }
public Member Member { get; set; }
public Category Category { get; set; }
public IList<Feature> Features { get; set; }
public IList<Picture> Pictures { get; set; }
public IList<Operation> Operations { get; set; }
}
public class AdCar : Ad
{
public int Kms { get; set; }
public Model Model { get; set; }
public Fuel Fuel { get; set; }
}
public class AdBoat : Ad
{
public int Hours { get; set; }
public string Model { get; set; }
}
我是否必须为每个子类构建特定的操作:
CreateAdCar()
CreateAdBoat()
或者我可以有类似的东西:
CreateAdCommon()
和CreateAdCar()
如何拆分这两个类,这样我就不必重复 Car Ad 类和 Boat Ad 类的所有代码?