取消删除标记为 EntityState.Delete 的实体?
让我用代码来谈谈:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于我认为这是一个错误,因此我将其报告给 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