Reputation: 481
I have a conceptual problem. It's about the correct Database architecture for persisting inherited objects. I'd like to have the proper way to do it, not using EF Code First, because this is all conceived beforehand, and is not necessarily used with EF, it may be, but not sure, or not only. I need a proper way which still will be consistant with ORM approaches, like Entity Framework.
Let's simplify and say we have an object called "Transportation Vehicle" : TransVehicle, it has following properties :
Let's say now we have a "Car" inheriting from the TransVehicle, which adds following properties :
We also have a "Plane" which adds those following other properties :
So, I may have in my code a List which will contain Cars and Planes.
I suppose I could have a table "TransVehicle" with fields like "Id, Name, Color, Age", then a table "Cars" with fields like "Id, FuelType, WheelSize", and a table "Planes" with fields "Id, EngineQuantity, MaxTakeOffWeight". I could say :
Which is good conceptual practice ? Have you other tips ? Which way will be easy to map in an ORM ?
Upvotes: 2
Views: 427
Reputation: 12849
This is common problem of mapping an object hierarchy to relational model. You can read about it all over the web.
You basically have three options:
Most ORMs do allow you to pick which one fits the hierarchy best or even mix and match between them for maximum performance or storage savings.
Upvotes: 1