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

前端 未结 10 1203
终归单人心
终归单人心 2020-11-27 14:48

I am getting this error \"The object cannot be deleted because it was not found in the ObjectStateManager.\"

My code is:

    protected MyEntities sql         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 15:37

    You should be sure that your object is exist in the list you are trying to remove from , you should put the following condition

    if(context.entity.contains(your object))

    remove it.

    if you have a complicated condition for equality you should override equal method in entity class to put your condition for equality , to get the right way for an extension method "entity.contains"

提交回复
热议问题