[英]EF6 Many to Many Delete Not working
I have two models [DOCTOR] & [CONTACTS] that are associated via a many-to-many relationship using Entityframework 6.0. 我有两个模型[DOCTOR]和[CONTACTS],它们使用Entityframework 6.0通过多对多关系进行关联。 I can add a doctor find with the following:
我可以添加以下内容的医生发现:
DM is a wrapper class around the doctor entity so that I can bind to it using onpropertychange. DM是围绕Doctor实体的包装器类,因此我可以使用onpropertychange绑定到它。
using (var context = new RxStoreEntities())
{
contact C = context.contacts.First(i => i.LoginID == loginID);
C.Doctors1.Add(DM.DOCTOR);
context.SaveChanges();
}
When I do the following to try to delete it, it will not delete. 当我执行以下操作尝试删除它时,它不会删除。 I even checked SQL Profiler and I am not seeing the delete SQL function like I should be seeing.
我什至检查了SQL事件探查器,但没有看到应有的删除SQL函数。 The code for the delete is as follows:
删除的代码如下:
using (var context = new RxStoreEntities())
{
contact C = context.contacts.First(i => i.LoginID == loginID);
C.Doctors1.Remove(DM.DOCTOR);
context.SaveChanges();
}
DM.DOCTOR isn't tracked by your context. 上下文未跟踪DM.DOCTOR。 Before SaveChanges, call:
在SaveChanges之前,请致电:
context.Doctors.Attach(DM.DOCTOR);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.