自加载实体以来,错误实体可能已被修改或删除。 [英] Error Entities may have been modified or deleted since entities were loaded

查看:99
本文介绍了自加载实体以来,错误实体可能已被修改或删除。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保存了超过50000条记录,这是一个很长的代码,所以我不能在这里复制。但总而言之,我收到以下错误,我也没有在本地收到此错误,但是实时上并非每次都收到此错误。我无法跟踪错误的确切行:-

I am saving more than 50000 records & it is a long code so i am not able to copy here. But in summary i am getting the following error, I am also not getting this error locally but on the live it is getting this error not every time. I am unable to trace the exact line of the error :-

错误:-


InOutImport POST错误消息错误消息:存储更新,插入或删除语句影响了意外的行数(0)。
自加载实体以来,实体可能已被修改或删除。
刷新ObjectStateManager条目。

Error in InOutImport POST Error Message : Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.

堆栈跟踪:-


在System.Data.Entity.Internal.InternalContext.SaveChanges()

at System.Data.Entity.Internal.InternalContext.SaveChanges()

我该如何解决此错误?

推荐答案

您遇到了 DbUpdateConcurrencyException 。这意味着您的实体可能具有 ROWVERSION ,该实体框架用于乐观并发。将数据持久保存到数据库后,EF会检查自从数据库检索数据以来数据是否已更改。这是有可能的,因为您的实体附带了 ROWVERSION

You have run into a DbUpdateConcurrencyException. That means your entities probably have a ROWVERSION which entity framework uses for optimistic concurrency. When your data is persisted to the DB, EF checks whether your data has changed since you have retrieved them from the database. That is possible because of the ROWVERSION that comes with your entites.

没有一种尺码适合的-此问题的所有解决方案。您如何解决它,取决于您的具体情况。检查此MSDN文章有关您的选择解决此问题。

There is no one-size-fits-all solution for this issue. How you have to resolve it, depends on your specific case. Check this MSDN article about your options in resolving this problem.

您可能要做的是检查 DbUpdateConcurrencyException.Entries 属性,以查看您的50000个实体中有哪些存在并发问题。

What you will probably have to do is to check the DbUpdateConcurrencyException.Entries property to see which of your 50000 entities have concurrency issues.

这篇关于自加载实体以来,错误实体可能已被修改或删除。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆