TPH Approach Service implementation

杀马特。学长 韩版系。学妹 提交于 2019-12-24 20:57:40

问题


What is the best aproach to develop a TPH based entity with Entity Framework, for example, if I have common fields in an Ads website, and specific ones:

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; }
}

Do I have to build specific operations for every subclass:

  • CreateAdCar()
  • CreateAdBoat()

Or can I have something like:

  • CreateAdCommon() and CreateAdCar()

How can I split the two classes so I don't have to repeat all the code for the Car Ad class and Boat Ad class?

来源:https://stackoverflow.com/questions/14174771/tph-approach-service-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!