Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Commented Issue: Code First: Allow subclasses to map field to same database column with TPH inheritance [583]

$
0
0
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

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>