Entity framework 4 add to many-to-many
- by mehanik
I have model whith 3 tabels and one is link table with additional field:
Groups
Id
Name
Users
Id
Name
Roles
Id
Name
LinkTable
Id
GroupId
UserId
RoleId
The quuestion is how to add 3 related entities:
Code bellow doesn't work.
using (var db = new dbEntities())
{
db.Groups.AddObject(Group.CreateGroup(1, "TestGroup"));
db.Users.AddObject(User.CreateUser(1, "AdminUser"));
db.Roles.AddObject(Role.CreateRole(1, "Admin"));
db.UserGroupRoles.AddObject(UserGroupRole.CreateUserGroupRole(1, 1, 1, 1));
db.SaveChanges();
}