"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
 
  

你可能感兴趣的:(自我心的)