EF 更新数据出现 System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: 异常
EF6更新 数据出现 System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0)....异常
先还原一下问题出现的场景;
首先,获取 数据倒view显示,并绑定到文本框显示,点击提交时候,出现上面异常信息;
数据更新错误,通常包含以下几种:
1,DbEntityValidationException
2,DbUpdateConcurrencyException(以上错误将被该异常捕获)
情况一:往往是数据格式不正确,比如,int32类型不可为空,却绑定null值,等等
情况二:也是本次要重点说的情况,可能情况有以下几种
1,数据并发情况下,多人客户端对同一条数据同时操作,如果是先delete,再update,那么,一定是会出现以上错误,反之,如果是先update再delete,完全不成问题,详见。。。。走马观花的博客 搜索标题中的异常信息。
2,就是本次要说的,也是本人遇到的问题,对于模型中,创建了并发标识字段,timestamp,此时,进行数据编辑的时候,
一定要注意,页面上一定要带上该字段值。否则必然出现以上错误,原因很简单,如果不带上这个标识,此时,更新数据 上下文中会检索并发标识,此时找不到相应实体信息的并发标识,可以理解……可以说提升到了并发的高度了吧,找不到同条数据,问题便会出现。
那么解决方法就有了,view中添加标识的隐藏字段即可,在编辑的时候将原数据的标识绑定上,后台提交数据时,重新赋值到实体。即可提交成功。


EF 更新数据出现 System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: 异常的更多相关文章
- ef添加数据时出错 System.Data.Entity.Infrastructure.DbUpdateConcurrencyException”类型的异常
找半天才找到 ef添加数据时出错原因:数据库表中没有主键 ,就算表中有自增列 Added方法也会报错: - this._db.SaveChanges() “this._db.SaveCh ...
- system.Data.Entity.Infrastructure.DbUpdateConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0) 问题
页面控件没有做限制.提交后还可以继续点击,造成了在短时间内的多次请求.查看日志两次错误在200ms之内. 错误信息 system.Data.Entity.Infrastructure.DbUpdate ...
- Mysql EF 触发器生成主键id 存储区更新、插入或删除语句影响到了意外的行数(0)。实体在加载后可能被修改或删除。刷新 ObjectStateManager 项 ;System.Data.Entity.Infrastructure.DbUpdateConcurrencyException
http://stackoverflow.com/questions/24725261/how-to-use-a-custom-identity-column-in-sql-with-entity-f ...
- System.Data.Entity.Infrastructure.DbUpdateException
异常描述: 捕捉到 System.Data.Entity.Infrastructure.DbUpdateException HResult=-2146233087 Message=无法更新 E ...
- code first System.Data.Entity.Infrastructure.CommitFailedException: An error was reported while committing a database transaction but it could not be determined whether the transaction succeeded
System.Data.Entity.Infrastructure.CommitFailedException: An error was reported while committing a da ...
- 报错:System.Data.Entity.Infrastructure.DbUpdateException 更新条目时出错
背景 往数据库添加数据,前端验证通过的情况下,提交报错,程序停在了SaveChanges()这行,并报如上错误. 分析 猜想是提交的领域模型不符合数据库要求,但不知道具体哪里出错.网上查资料,有人发现 ...
- .net mvc System.Web.Optimization 、System.Data.Entity.Infrastructure找不到
在MVC4的开发中,如果在App_Start目录下BundleConfig.cs类没有找不到引用System.Web.Optimization,可以使用程序包管理控制台进行安装到使用的项目 打开 工具 ...
- MVC+EF 序列化类型为“System.Data.Entity.DynamicProxies.__的对象时检测到循环引用
用MVC+EF做简单查询时,返回json格式数据出现问题 原代码: public ActionResult JSon({ NorthwindEntities db = new NorthwindEnt ...
- 【model模型传入view的数据类型错误】传入字典的模型项的类型为“System.Data.Entity.Infrastructure.DbQuery`1[MapScience.PovertyAlleviation.Web.Models.Qu
出现这个问题的原因是控制器中传给view的数据类型与View中设置的model类型不一致导致,比如控制器返回的IList类型的,而你在View里面model设置的是IEnumerable<> ...
随机推荐
- 在非UI线程中更改UI(Delphi使用隐藏窗口来处理,QT使用信号槽)
在Delphi里我记得是使用TThread.Synchronize(TThreadMethod),原理是利用了一个隐藏窗口来处理. 在QT Debug模式一下,碰到了同样的问题,显示错误: canno ...
- Android Studio 运行、编译卡死的解决办法
Android stuido作为google主推的IDE,配合gradle编译,有很多的优点和便捷性.唯一使用过程中不舒服的地方就是莫名其妙的卡顿,经常在Gradle Build的时候卡死强制重启电脑 ...
- 【HDOJ】1455 Sticks
DFS.搜索以棍数为条件循环搜索较好,这样不会超时. #include <stdio.h> #include <string.h> #include <stdlib.h& ...
- error: /lib64/libc.so.6: symbol _dl_starting_up, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference
]$ sudo yum install libnotify*Loaded plugins: fastestmirror, refresh-packagekit, securitySetting up ...
- (转载)Mysql中,SQL语句长度限制
(转载)http://qjoycn.iteye.com/blog/1288435 今天发现了一个错误:Could not execute JDBC batch update 最后发现原因是SQL语句长 ...
- 实现DataGridView实时更新数据
;).ToString() + ).ToString() + "秒"; } }}
- iOS设备保持横排方向
//保持横排方向 -(NSUInteger)supportedInterfaceOrientations{ returnUIInterfaceOrientationMaskLandscapeL ...
- JavaScript 类型判断 —— typeof 以及 instanceof 中的陷阱
JavaScript中基本类型包含Undefined.Null.Boolean.Number.String以及Object引用类型.基本类型可以通过typeof来进行检测,对象类型可以通过instan ...
- SRM 409(1-250pt, 1-500pt)
DIV1 250pt 题意:称string s是vector<string> words的ordered superstring,如果它满足:存在一个数列{x0, x1, x2...xm} ...
- record
http://www.cnblogs.com/90zeng/p/python_translation.html http://www.cnblogs.com/netfocus/p/4478094.ht ...