We have an entity like Vehicle
and three derived entities such as Car
, Motorbike
and Bicycle
.
This inheritance hierarchy is implemented with TPH.
Here are entity mapping conditions:
__disc__ = car
for Car__disc__ = motorbike
for Motorbike__disc__ = bicycle
for BicycleHow can I derive another child from
Vehicle
likeMotorVehicle
with following mapping condition:__disc__ = car OR motorbike
for MotorVehicle
I'd view in Database like this when I had this structure with TPT:
SELECT Id
FROM Vehicles
WHERE (__Disc__ = N'car') OR (__Disc__ = N'motorbike')
I think this view is not required with TPH.
Please note that I can not change the inheritance like this: Vehicle<-- MotorVehicle<-- Car. Don't think about injecting the motor vehicles as the parent of car and other children because Car and Motorbike and Bicycle are already exists. I just want to assign some business to all motor vehicles.
Why couldn't you introduce a
MotorVehicle
level in the class hierarchy? You can. It's just an abstract class, so it doesn't need a discriminator value. EF hardly notices the class!I tried both with and without the
MotorVehicle
class and the database structure and the number of defined discriminators was the same in both cases.Edit
This is what I did: