Search for existing suggestions

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

Scenario in the post http://entityframework.codeplex.com/workitem/583 works only for columns that are not foreign keys.

For example we have BaseEntity and three inherited entities:
InheritedEntity1.Name
InheritedEntity2.SpecialStatus
InheritedEntity3.SpecialStatus

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
(thinking…)
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 →

0 comments

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base