I had the following entities in my domain:
And this is how it was mapped through Entity Framework:
Unfortunately Entity Framework got confused when I tried to create a new Role and RoleAssignment. It generated the wrong query for the RoleAssignment and tried to set the “Id” field to the Role id.
To fix it I had to explicitly tell Entity Framework to use the Role_Id column to map the foreign key relationship:
Strange thing is that this code was working in a previous release of the application.