I am trying to map a TPT inheritance hierarchy on a legacy database (I can't change column names). All of the examples have the primary keys of the parent and children tables with the same name. Unfortunately, mine doesn't behave this way.
As a simplified example:
Vehicle
----------------
VehicleId
Make
Model
----------------
Car
----------------
CarId
SomeOtherField
----------------
CarId and VehicleId are actually the same id and are the values that should be used to associate the tables. Is there any support for creating this as a TPT relationship in Code First?
Here is a statement about this issue from the EF team:
Unfortunately this isn't possible at this stage. I realize this isn't a great answer but one option would be to create a view that renames the PK/FK column and then map to that.
It's from February 2011. So it was related to an earlier CTP version of EF Code-First. But I believe that this scenario is still not supported in EF 4.1.
Also a similar question here with not satisfying result regarding EF 4.1 Code-First: How can I use TPT inheritance models when primary keys have different names?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With