Rune
Rune

Reputation: 8380

Using a navigation property as discriminator in a TPH inheritance scenario in Entity Framework 4

I am trying to create a TPH inheritance hierarchy using foreign keys / navigation properties as discriminators and I am having some trouble getting it right.

I have the following entities:

Person:
  Id (int)
  Name (nvarchar)
  PlaneId (int)
  CarId (int)

Car:
  Id (int)
  Name (nvarchar)

Plane:
  Id (int)
  Name (nvarchar)

with PlaneId and CarId beign FKs. I have corresponding tables in a database and I can create a conceptual model using the VS2010 EF wizard. The Person entity then has two navigation properties, Car and Plane.

Now I want to derive two types from Person:

Pilot (condition: PlaneId is not null)
Driver (condition: CarId is not null)

So, I add the entity Pilot, tell it to map to Person and add the condition PlaneId is not null. At this point Visual Studio (or edmgen I guess) complains that the property Person.PlaneId with 'IsNull=false' condition must be mapped.

What is my next step? I have tried various approaches, but can't seem to get it to work. Any insight would be greatly appreciated.

Upvotes: 0

Views: 748

Answers (1)

Craig Stuntz
Craig Stuntz

Reputation: 126587

You can't do that. Discriminator columns must be non-nullable.

Upvotes: 2

Related Questions