Entity framework 4 add to many-to-many
Posted
by mehanik
on Stack Overflow
See other posts from Stack Overflow
or by mehanik
Published on 2010-04-19T08:58:06Z
Indexed on
2010/04/19
9:03 UTC
Read the original article
Hit count: 203
many-to-many
|entity-framework
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();
}
© Stack Overflow or respective owner