TPH方法服务实施

时间:2013-01-05 18:09:49

标签: c# asp.net-mvc entity-framework inheritance

使用Entity Framework开发基于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类的所有代码?

0 个答案:

没有答案