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

发布于 2024-08-11 05:22:07 字数 660 浏览 3 评论 0原文

让我用代码来谈谈:

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)

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?

I tried:

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

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.

Important Table structure:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠北森屋 2024-08-18 05:22:07

由于我认为这是一个错误,因此我将其报告给 Microsoft,请投票并分享您的想法: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=513174

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文