When using TPH inheritance, Code First requires every field defined in a subclass to be mapped to a unique database column. However, there are scenarios where it would be simpler for subclasses to map fields to the same column. For example:
public abstract class Vehicle { ... }
public class Car : Vehicle { ... }
public class Truck : Vehicle { ... }
public class Trike : Vehicle { public string WheelOrientation { get; set; } ... }
public class CanAmSpyder : Vehicle { public string WheelOrientation { get; set; } ... }
Given the above example with Code First TPH, the database table "Vehicle" would require two columns for wheel orientation: "TrikeWheelOrientation" and "CanAmSpyderWheelOrientation". But having a single "WheelOrientation" column that both the Trike subclass and CanAmSpyder subclass can map to seems cleaner.
public abstract class Vehicle { ... }
public class Car : Vehicle { ... }
public class Truck : Vehicle { ... }
public class Trike : Vehicle { public string WheelOrientation { get; set; } ... }
public class CanAmSpyder : Vehicle { public string WheelOrientation { get; set; } ... }
Given the above example with Code First TPH, the database table "Vehicle" would require two columns for wheel orientation: "TrikeWheelOrientation" and "CanAmSpyderWheelOrientation". But having a single "WheelOrientation" column that both the Trike subclass and CanAmSpyder subclass can map to seems cleaner.