I have a requirement to build a slightly unusual data model, but I’m having trouble persuading Entity Framework Code First to map it for me.
I have two entities – ‘A’ and ‘B’.
‘B’ is a type of ‘A’, which is why I’m trying to get inheritance working.
However, multiple versions of ‘B’ may exist.
I would like to model this by having a shared ID column in each of the tables for ‘A’ and ‘B’, but for ‘B’ to also have a ‘Version Number’ field which makes a combined key with the ID.
So – this would be a one-to-many inheritance type of arrangement.
Ultimately the goal for this would be to be able to retrieve a specific ‘B’ entity and for it to also contain all of the properties and methods of the related ‘A’ entity without having to go via another object.
Any ideas would be great.
Thanks,
Chris
Inheritance in EF is always one-to-one. If you have one-to-many you must handle it as relation or build your own intermediate layer which will hide EF implementation by your own domain model (which will take related objects from EF and create your own inherited object).