Search for existing suggestions

Allow foreign key columns to be shared between a subset of TPH subclasses

Scenario in the post works only for columns that are not foreign keys.

For example we have BaseEntity and three inherited entities:

SpecialStatus is entity stored in separate table.

BaseEntity table will have columns 'Name', 'SpecialStatus_Id', 'SpecialStatus_Id1'

Try to change the name of the column:
modelBuilder.Entity<InheritedEntity2>().HasOptional(p => p.SpecialStatus).WithOptionalDependent().Map(i => i.MapKey("SpecialStatus_Id"))
modelBuilder.Entity<InheritedEntity3>().HasOptional(p => p.SpecialStatus).WithOptionalDependent().Map(i => i.MapKey("SpecialStatus_Id"))

and get an ModelValidationException:
"One or more validation errors were detected during model generation:
SpecialStatus_Id: Name: Each property name in a type must be unique. Property name 'SpecialStatus_Id' is already defined.

3 votes
Sign in
Sign in with: Facebook Google
Signed in as (Sign out)

We’ll send you updates on this idea

Denis shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Sign in with: Facebook Google
Signed in as (Sign out)

Feedback and Knowledge Base