Reputation: 36573
Is this possible?
I have User and Provider entities. A User may or may not be a Provider (could just be an Assistant) and a Provider may or may not be a User (it could be a Location).
The designer lets me model this, but it won't validate because of the key properties. Is this possible to achieve with EF?
Upvotes: 1
Views: 210
Reputation: 364279
No it is not because one-to-one relation in EF is always modeled through the primary key. Dependent entity must have foreign key constraint to principal entity placed on its primary key. It always result in 0..1 to 1 where principal can have one or none dependent but dependent must have a principal because it must have a primary key value and that value has referential constraint to principal entity.
Btw. I'm not sure if this can be even modeled in the database because even with unique key null value is still considered as one of unique values so only single record can have a value set to null when you also have unique index on that column.
Upvotes: 2