Entity framework 取消删除标记为EntityState的实体。是否删除?
让我用代码代替对话:Entity framework 取消删除标记为EntityState的实体。是否删除?,entity-framework,many-to-many,entity-relationship,navigation-properties,Entity Framework,Many To Many,Entity Relationship,Navigation Properties,让我用代码代替对话: Dim Contact = Context.Contacts.Include("Phones") Dim phone = Contact.Phones(0) Contact.Remove(phone) 现在如何刷新上下文,取消上次删除关系 我试过: Context.Refresh(RefreshMode.StoreWins, phone) 'Doesn't recover the relation Context.Refresh(RefreshMode.StoreWins
Dim Contact = Context.Contacts.Include("Phones")
Dim phone = Contact.Phones(0)
Contact.Remove(phone)
现在如何刷新上下文,取消上次删除关系
我试过:
Context.Refresh(RefreshMode.StoreWins, phone) 'Doesn't recover the relation
Context.Refresh(RefreshMode.StoreWins, _
ObjectStateManager.GetObjectStateEntries(EntityState.Deleted))
最后一个引发InvalidOperationException:
要刷新的对象集合中索引0处的元素具有null EntityKey属性值或未附加到此ObjectStateManager
重要表格结构:
联系人:姓、名电话:号码,备注
ContactPhone(多对多):ContactId(nav),PhoneId(nav)由于我认为这是一个bug,我向Microsoft报告了它。请投票并分享您的想法: