"The object cannot be deleted because it was not found in the ObjectStateManager."

最近优化EF的性能时遇到一个问题, 当在EF生成的Entityes的构造里加上:
this.protocolnodes.MergeOption = MergeOption.NoTracking;this.protocolversionhistories.MergeOption = MergeOption.NoTracking;

调用DeleteObject时,会导致"The object cannot be deleted because it was not found in the ObjectStateManager."错误。

解决办法为, 先调用entity实例的Attach(deleteObj),参数为要删除的对象,然后调用ObjectStateManager.ChangeObjectState(deleteObj, EntityState.Deleted),

具体参考
http://www.cnblogs.com/Benjamin/archive/2012/10/24/2736739.html

posted @ 2013-07-03 18:33  muzizongheng  阅读(644)  评论(0编辑  收藏  举报
如果我们时时忙着展现自己的知识, 将何从忆起成长所需的无知?