Hi
I have found a possible bug in a Many To Many scenario. The following code throws the following exception.
Violation of PRIMARY KEY constraint 'PK_SystemFunctions'. Cannot insert duplicate key in object 'dbo.SystemFunctions'.
|
I merely remove an entity and then add another entity and then add the removed enitity again. This is not suppose to trigger any inserts since the record was not deleted but only removed and added in memory. Also when I use only EF the error goes away and it works.
var role = DemoDBEntities.DefaultManager.Roles.Where(r => r.Name == "RoleA").FirstOrDefault();
var remSystemfunction = role.SystemFunctions[0];
var systemFunctionToAdd = DemoDBEntities.DefaultManager.SystemFunctions. Where(sf => sf.Name == "SystemFunctionC").FirstOrDefault();
role.SystemFunctions.Remove(remSystemfunction); role.SystemFunctions.Add(systemFunctionToAdd); role.SystemFunctions.Add(remSystemfunction);
DemoDBEntities.DefaultManager.SaveChanges();
|
I have attached a sample project along with a sql file to generate the database and some dummy records.
uploads/988/ManyToManyBug.rar