How to delete entity in many-to-many relationship using POCOs

后端 未结 1 796
野性不改
野性不改 2021-01-17 02:12

I\'m using POCOs in combination with EF4 and some entities are in many-to-many relationships, in my case objects of class User and objects of class PrivilegeGroup.

1条回答
  •  被撕碎了的回忆
    2021-01-17 03:01

    Interesting question. Here is how u do it.

    var user = new User { UserId = 1 };
    var admin = new Privilege { PrivilegeId = 1 };
    user.Privileges.Add(admin);
    db.Users.Attach(user);
    user.Privileges.Remove(admin);
    db.SaveChanges();
    

    There are total of 4 different approaches to solving the same problem. but i think from what u are telling me, this should suffice but if u need more info, you can ping me directly through mail

    0 讨论(0)
提交回复
热议问题