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

只愿长相守 提交于 2019-12-01 14:45:32

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!