Search code examples
entity-frameworkt-sqlmany-to-manyedmx

Entity Framework 6.x Must specify mapping for all key properties


I am beginning playing with EF 6.x and I've got an annoying issue.

I've designed a database with simple User,Role,Permissions tables each one bond to another with classic many-to-many relation.

EF wants me to create primary keys in indirect tables (UserPermissions etc.) but also wants me to make some mapping for those Primary Keys but I have no clue why.

Is there something wrong with my design or there Is a workaround to this issue? Maybe Can I in some way use Unique index instead of Primary Key to satisfy EF?

There you have diagram to make it more clear:

enter image description here


Solution

  • Well, I'm embarrased that I've not came up to solution earlier.

    Just added multicolumn Primary Key on columns referencing direct tables via foreign key.

    e.g. CONSTRAINT pk_IdRole_IdPermission_RolePermissions PRIMARY KEY (IdRole,IdPermission)