问题
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()andCreateAdCar()
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