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.
Comments: Adding a reference to the same item in our UserVoice site: https://data.uservoice.com/admin/forums/72025-entity-framework-feature-suggestions/suggestions/2519564-allow-columns-to-be-shared-between-a-subset-of-tph And in StackOverflow: http://stackoverflow.com/questions/4389227/entity-framework-4-ctp5-code-first-how-to-share-common-column-names-in-a-hierar
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.
Comments: Adding a reference to the same item in our UserVoice site: https://data.uservoice.com/admin/forums/72025-entity-framework-feature-suggestions/suggestions/2519564-allow-columns-to-be-shared-between-a-subset-of-tph And in StackOverflow: http://stackoverflow.com/questions/4389227/entity-framework-4-ctp5-code-first-how-to-share-common-column-names-in-a-hierar