[英]EF6 Many to Many Delete Not working
我有两个模型[DOCTOR]和[CONTACTS],它们使用Entityframework 6.0通过多对多关系进行关联。 我可以添加以下内容的医生发现:
DM是围绕Doctor实体的包装器类,因此我可以使用onpropertychange绑定到它。
using (var context = new RxStoreEntities())
{
contact C = context.contacts.First(i => i.LoginID == loginID);
C.Doctors1.Add(DM.DOCTOR);
context.SaveChanges();
}
当我执行以下操作尝试删除它时,它不会删除。 我什至检查了SQL事件探查器,但没有看到应有的删除SQL函数。 删除的代码如下:
using (var context = new RxStoreEntities())
{
contact C = context.contacts.First(i => i.LoginID == loginID);
C.Doctors1.Remove(DM.DOCTOR);
context.SaveChanges();
}
上下文未跟踪DM.DOCTOR。 在SaveChanges之前,请致电:
context.Doctors.Attach(DM.DOCTOR);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.