Mates,
I have a SQL Server table <entity> which is in a certain administration. The table <entity> has a relation with <entitystatus>.
<entity>
Id (int, PK, auto-increment)
AdminstrationId int
Status int
Name varchar
....
<entitystatus>
Id (int, PK, auto-increment)
AdminstrationId int
Number int
Name varchar
As you can see, both tables have a Id field which is a PK and have auto-increment on.
Now I want entity framework to create a relation between both AdministrationId fields, and the <entity>.Status & <entitystatus>Number field.
How can I do this?
The code below in the 'what have you tried', actually works for the relation, but it removes the Id field as a PK of the status table. This causes an error when I enter new status values in the <entitystatus> table
What I have tried:
modelBuilder.Entity<Entity>()
.HasKey(c => new { c.AdministrationId, c.Number });
modelBuilder.Entity<Entity>()
.HasRequired(p => p.EntityStatus)
.WithMany(x => x.Entities)
.HasForeignKey(p => new { p.AdministrationId, p.Status });