取消删除标记为EntityState.Delete的实体?

Shi*_*mmy 7 entity-relationship many-to-many entity-framework navigation-properties

而不是说话让我谈谈代码:

Dim Contact = Context.Contacts.Include("Phones")
Dim phone = Contact.Phones(0)
Contact.Remove(phone)
Run Code Online (Sandbox Code Playgroud)

如何刷新上下文,取消上一次关系删除?

我试过了:

Context.Refresh(RefreshMode.StoreWins, phone) 'Doesn't recover the relation
Context.Refresh(RefreshMode.StoreWins, _
    ObjectStateManager.GetObjectStateEntries(EntityState.Deleted))
Run Code Online (Sandbox Code Playgroud)

最后一个抛出InvalidOperationException:要刷新的对象集合中索引0处的元素具有空EntityKey属性值或未附加到此ObjectStateManager.

重要的 表格结构:

联系人:FirstName,LastName
电话:号码,注意
ContactPhone(多对多):ContactId(nav),PhoneId(nav)

Shi*_*mmy 4

因为我认为这是一个错误,所以我向 Microsoft 报告了它,请投票并分享您的想法:http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx ?FeedbackID=513174