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


 

 错误信息

System.InvalidOperationException:“The object cannot be deleted because it was not found in the ObjectStateManager.”

对象状态管理器 ObjectStateManager 不存在该对象,不可删除!

 

图片

 

解决方案

 

C# 全选
  public virtual int Remove<T>(List<T> entities) where T : class
        {
            //对象状态管理器设置【删除】状态           
            foreach (var obj in entities)
            {
                _dbContext.Entry(obj).State = EntityState.Deleted;
            }

            //删除
            _dbContext.Set<T>().RemoveRange(entities);

            return SaveChanges(false);
        }

 

版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
C/S框架网
上一篇:An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()'
下一篇:GIT克隆VS源码下来,打开解决方案发现引用全部是黄色叹号,无法编译
评论列表

发表评论

评论内容
昵称:
关联文章

The object cannot be deleted because it was not found in the ObjectStateManager
FastReport报错:TfrxReportClass cold not be found!
System.NotSupportedException:“The entity or complex type 'CSFramework.EF.tb_MyUser' cannot be constructed in a LINQ to Entities query.”
The server factory could not be located for the given input: Microsoft.Owin.Host.HttpListener
Entity Framework(EF):测试DbContext.Remove方法,对象状态管理器(Object State Manager)
The Database principal owns a schema in the database
SQL:Cannot resolve the collation conflict (字符集冲突)
Cannot resolve the collation conflict.无法解析等号两边的中文简体和中文繁体字符集
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'
How to changing the asp.net development server port?
Object Collection Editor窗体的Add/Delete按钮不可用
打开设计窗体报错:To prevent possible data loss before loading the designer
C#.Net对象内存模型及堆/栈数据结构详解 (四)
Your project does not reference ".NETFramework,Version=v4.7.2" framework.
C#.Net对象内存模型及堆/栈数据结构详解 (一)
Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the s
C#实现SQL查询分析器(C# Visual SQL Query Designer)
the pre-login handshake. (provider: SSL Provider, error: 0
C#数据库本地缓存技术(Database local cache)
C#中 object类型,c# object