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

前端 未结 10 1216
终归单人心
终归单人心 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:47

    I got this problem and solve it. Just copy below code:

    sqlEntities.Attach(entity);
    sqlEntities.Remove(entity);
    sqlEntities.SaveChanges();
    

提交回复
热议问题