取消删除实体 [英] Undeleting Entities

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

问题描述

我很惊讶没有其他人似乎问过这个问题,但是因为ObjectContext.DeleteObject方法只是在调用SaveChanges之前将对象标记为删除,所以可以在提交到DB之前取消标记以进行删除。

I am surprised no-one else seems to have asked this question, but since the ObjectContext.DeleteObject method only marks the object for deletion until SaveChanges is called, is it possible to un-mark it for deletion before commiting to the DB.


推荐答案

遗憾的是不行 - State属性是只读的,SetModified()无法在Deleted上调用对象。您可以尝试拆卸和附加物体 - 但它不会恢复关系。

That unfortunately won't work - State property is read-only and SetModified() cannot be called on Deleted objects. You can try detaching and attaching the object - but it won't resurrect the relationships.



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

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