This question is locked. New answers and comments are not allowed.
Hello,
I have many to many mapping on basis tables:
Roles
Id int, PK
Name varchar(50), not null
Privileges
Id int, PK
Name varchar(50), not null
RolePrivileges
RoleId int, PK, FK to Roles.Id
PrivilegeId int, PK, FK to Privileges.Id
I have existing privileges (in table Privileges) and I'd like to insert a new Role with selected privileges.
I try someting like this:Role role = new Role(); role.Name = "Role ABC"; role.Privileges.Add(new Privilege { Id = 1, Name = "Privilege 1" }); role.Privileges.Add(new Privilege { Id = 3, Name = "Privilege 3" }); dbContext.AddRole(role);After this I get error Telerik.OpenAccess.Exceptions.DuplicateKeyException because it tries to insert
new privileges (to Privileges table) instead of to insert new row to RolePrivileges table.
Regards
k