取消删除标记为EntityState.Delete的实体? [英] Undelete an entity marked as EntityState.Delete?

查看:99
本文介绍了取消删除标记为EntityState.Delete的实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我与代码交谈而不是交谈:

instead of talking let me talk with code:

Dim Contact = Context.Contacts.Include("Phones")
Dim phone = Contact.Phones(0)
Contact.Remove(phone)

我现在如何刷新上下文,取消上一个关系删除?

How do I refresh the context now, canceling last relation deletion?

我尝试过:

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

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

the last one throws an InvalidOperationException: The element at index 0 in the collection of objects to refresh has a null EntityKey property value or is not attached to this ObjectStateManager.

重要 表结构:

联系人:名字,姓氏
电话:编号,备注
ContactPhone (多对多):ContactId(nav),PhoneId(nav)

Contact: FirstName, LastName
Phone: Number, Note
ContactPhone (many-to-many): ContactId (nav), PhoneId (nav)

推荐答案

由于我认为这是一个错误,因此我向Microsoft报告了此错误,请投票并分享您的想法:

Since I believe this is a bug, I reported it to Microsoft please vote and share your ideas: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=513174

这篇关于取消删除标记为EntityState.Delete的实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆