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: Thanks Arthur Vickers and team for fixing this issue. I was in the middle of designing some complex entities and this bug was causing my tables to have many unnecessary columns with ugly names. Trying to design around this by adding a level of inheritance on my classes so as to share the common properties was making making my classes' inheritance hierarchy very messy. I got information from @ajcvickers on twitter. The fact that it came on April 1 had me worried I could be getting pranked. Had to check to make sure it was true. Again, thanks for fixing this issue.

Viewing all articles
Browse latest Browse all 10318

Trending Articles



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