FK Property Name on Assocition
Posted: Wed 09 Nov 2011 14:15
I have two classes Task and UserMaster.
The Task class needs two properties called CreateUser and UpdateUser, I would like to have these both be associated with UserMaster (Who's primary key is UserPK).
When I try to make the first association, a FK property is added to Task called UserPK. If I rename this to CreateUser, I get the following error:
So I removed the association and tried:
add a CreateUser property to the Task class
In the Association Editor, deselect 'Add Foreign Key Properties...'
Choose the CreateUser property from the dropdown.
I get the same error. The generated code is:
The Task class needs two properties called CreateUser and UpdateUser, I would like to have these both be associated with UserMaster (Who's primary key is UserPK).
When I try to make the first association, a FK property is added to Task called UserPK. If I rename this to CreateUser, I get the following error:
Code: Select all
Tracker.Task' does not contain a definition for 'UserPK' and no extension method 'UserPK' accepting a first argument of type 'Tracker.Task' could be found (are you missing a using directive or an assembly reference?)
add a CreateUser property to the Task class
In the Association Editor, deselect 'Add Foreign Key Properties...'
Choose the CreateUser property from the dropdown.
I get the same error. The generated code is:
Code: Select all
modelBuilder.Entity()
.HasRequired(p => p.UserMaster)
.WithMany(c => c.Tasks)
.HasForeignKey(p => new { p.UserPK })
.WillCascadeOnDelete(false);