实体框架:"存储更新,插入或删除语句影响的行(0)QUOT意想不到的数量。 [英] Entity Framework: "Store update, insert, or delete statement affected an unexpected number of rows (0)."

查看:1623
本文介绍了实体框架:"存储更新,插入或删除语句影响的行(0)QUOT意想不到的数量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用实体框架来填充网格控件。有时,当我进行更新,我得到了以下错误:

I am using Entity Framework to populate a grid control. Sometimes when I make updates I get the following error:

商店更新,插入或删除语句影响的行(0)的一个意想不到的数量。实体可能已被修改或删除,因为实体被装。刷新ObjectStateManager条目。

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.

我无法弄清楚如何重现此。但它可能是与我怎么并拢进行更新。有没有人看到了这一点,或有没有人知道该错误信息是指什么?

I can't figure out how to reproduce this. But it might have something to do with how close together I make the updates. Has anyone seen this or does anyone know what the error message refers to?

编辑:不幸的是,我可以自由地再现我是有在这里,因为我是从这个项目中走开,不记得,如果我最终找到了解决办法,如果其他开发人员固定它的问题,或者我的工作不再周围。因此,我不能接受任何答案。

Unfortunately I am no longer at liberty to reproduce the problem I was having here, because I stepped away from this project and don't remember if I eventually found a solution, if another developer fixed it, or if I worked around it. Therefore I cannot accept any answers.

推荐答案

这就是所谓的乐观并发功能的副作用。

That's a side-effect of a feature called optimistic concurrency.

不是100%确定如何将其打开/关闭实体框架,但基本上是它告诉你的是,当你抓住了数据从数据库中,当您保存您的更改别人已经改变了数据之间(这意味着当你去保存它0行实际上得到更新)。在SQL方面,它们的更新查询的,其中子句包含该行中每个字段的原始值,如果0行受到影响它知道有什么地方出了问题。

Not 100% sure how to turn it on/off in Entity Framework but basically what it's telling you is that between when you grabbed the data out of the database and when you saved your changes someone else has changed the data (Which meant when you went to save it 0 rows actually got updated). In SQL terms, their update query's where clause contains the original value of every field in the row, and if 0 rows are affected it knows something's gone wrong.

这背后的想法是,你会不会最终覆盖您的应用程序根本不知道发生了变化 - 它基本上由.NET上的所有更新扔在一个小的安全措施

The idea behind it is that you won't end up overwriting a change that your application didn't know has happened - it's basically a little safety measure thrown in by .NET on all your updates.

如果是一致的,赔率是它的发生你自己的逻辑中(EG:你实际上是在更新自己的数据的另一种方法在两者之间的选择和更新),但它可能是两个应用程序之间简单的竞争条件

If it's consistent, odds are it's happening within your own logic (EG: You're actually updating the data yourself in another method in-between the select and the update), but it could be simply a race condition between two applications.

这篇关于实体框架:"存储更新,插入或删除语句影响的行(0)QUOT意想不到的数量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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