Entity framework 在保存更改时获取实体框架中的错误

Entity framework 在保存更改时获取实体框架中的错误,entity-framework,Entity Framework,我得到了这个错误: 类型的例外 'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' 在EntityFramework.dll中发生,但未在用户代码中处理 附加信息:存储更新、插入或删除语句 受影响的行数意外(0)。实体可能已经 自加载实体后已修改或删除。刷新 ObjectStateManager条目 你知道这里出了什么问题吗 谢谢 我的堆栈跟踪是: [OptimisticConcurrencyException: St

我得到了这个错误:

类型的例外 'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' 在EntityFramework.dll中发生,但未在用户代码中处理

附加信息:存储更新、插入或删除语句 受影响的行数意外(0)。实体可能已经 自加载实体后已修改或删除。刷新 ObjectStateManager条目

你知道这里出了什么问题吗

谢谢

我的堆栈跟踪是:

[OptimisticConcurrencyException: 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.Core.Mapping.Update.Internal.UpdateTranslator.ValidateRowsAffected(Int64 rowsAffected, UpdateCommand source) +232
   System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +493
   System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut) +32
   System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(T noChangesResult, Func`2 updateFunction) +272
   System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() +143
   System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35() +34
   System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +448
   System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) +219
   System.Data.Entity.Core.Objects.<>c__DisplayClass2a.<SaveChangesInternal>b__27() +71
   System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +213
   System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) +408
   System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) +39
   System.Data.Entity.Internal.InternalContext.SaveChanges() +320

[DbUpdateConcurrencyException: 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() +366
   System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +56
   System.Data.Entity.DbContext.SaveChanges() +52
   Clase5.Data.ProductoRepositorio.Insertar(Producto producto) in c:\Users\Juan\Downloads\Clase_5_-_Codigo_fuente\Clase5\Clase4\Data\ProductoRepositorio.cs:27
   Clase5.Controllers.ProductoController.TresCrearProducto(Producto producto) in c:\Users\Juan\Downloads\Clase_5_-_Codigo_fuente\Clase5\Clase4\Controllers\ProductoController.cs:43
   lambda_method(Closure , ControllerBase , Object[] ) +180
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +211
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9657896
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
[OptimisticConcurrencyException:Store update、insert或delete语句影响了意外的行数(0)。自加载实体后,实体可能已被修改或删除。请刷新ObjectStateManager条目。]
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.ValidateRowsInfected(Int64行受影响,UpdateCommand源)+232
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()+493
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.b__2(UpdateTranslator ut)+32
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(T noChangesResult,Func`2 updateFunction)+272
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()+143
System.Data.Entity.Core.Objects.ObjectContext.b__35()+34
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 Func,IDBEcutionStrategy executionStrategy,Boolean startLocalTransaction,Boolean releaseConnectionOnSuccess)+448
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions选项、IDBEcutionStrategy executionStrategy、Boolean startLocalTransaction)+219
System.Data.Entity.Core.Objects.c__DisplayClass2a.b__27()+71
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1操作)+213
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions选项,布尔值executeInExistingTransaction)+408
System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions)+39
System.Data.Entity.Internal.InternalContext.SaveChanges()+320
[DbUpdateConcurrencyException:存储更新、插入或删除语句影响了意外的行数(0)。自加载实体后,实体可能已被修改或删除。请刷新ObjectStateManager条目。]
System.Data.Entity.Internal.InternalContext.SaveChanges()+366
System.Data.Entity.Internal.LazyInternalContext.SaveChanges()+56
System.Data.Entity.DbContext.SaveChanges()+52
c:\Users\Juan\Downloads\Clase\u 5\u-\u Codigo\u fuente\Clase5\Clase4\Data\ProductoRepositorio.cs:27中的Clase5.Data.ProductoRepositorio.Insertar(Producto-Producto)
c:\Users\Juan\Downloads\Clase\u 5\u-\u Codigo\u fuente\Clase5\Clase4\Controllers\ProductoController.trescrealProducto(Producto-Producto)中的Clase5.Controllers.ProductoController.cs:43
lambda_方法(闭包、控制器基、对象[])+180
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,对象[]参数)+14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数)+211
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数)+27
System.Web.Mvc.Async.c__显示类42.b__41()+28
System.Web.Mvc.Async.c_uuuudisplayClass8`1.b_uuuu7(IAsyncResult)+10
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+48
System.Web.Mvc.Async.c__显示类39.b__33()+57
System.Web.Mvc.Async.c__DisplayClass4f.b__49()+223
System.Web.Mvc.Async.c__显示类37.b__36(IAsyncResult asyncResult)+10
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+48
System.Web.Mvc.Async.c__DisplayClass2a.b__20()+24
System.Web.Mvc.Async.c__显示类25.b__22(IAsyncResult asyncResult)+102
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+43
System.Web.Mvc.c__;u displayClassId.b__u18(IAsyncResult asyncResult)+14
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+57
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+47
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)+10
System.Web.Mvc.c__;u DisplayClass8.b__;u 3(IAsyncResult asyncResult)+25
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+47
System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9657896
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+155

您已经在
Producto
实体中实现了字段级并发。转到
Producto
实体的EDMX设计器。逐个检查每列的属性。在可视化实体设计器中选择列->按F4键。检查属性
并发模式的值
。它应该设置为“无”。请查看以下快照作为我的一个实体
员工的示例。如果对于任何列,您看到的值为
Fixed
,那么这就是错误的根本原因

如果你真的在想
[OptimisticConcurrencyException: 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.Core.Mapping.Update.Internal.UpdateTranslator.ValidateRowsAffected(Int64 rowsAffected, UpdateCommand source) +232
   System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +493
   System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut) +32
   System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(T noChangesResult, Func`2 updateFunction) +272
   System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() +143
   System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35() +34
   System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +448
   System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) +219
   System.Data.Entity.Core.Objects.<>c__DisplayClass2a.<SaveChangesInternal>b__27() +71
   System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +213
   System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) +408
   System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) +39
   System.Data.Entity.Internal.InternalContext.SaveChanges() +320

[DbUpdateConcurrencyException: 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() +366
   System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +56
   System.Data.Entity.DbContext.SaveChanges() +52
   Clase5.Data.ProductoRepositorio.Insertar(Producto producto) in c:\Users\Juan\Downloads\Clase_5_-_Codigo_fuente\Clase5\Clase4\Data\ProductoRepositorio.cs:27
   Clase5.Controllers.ProductoController.TresCrearProducto(Producto producto) in c:\Users\Juan\Downloads\Clase_5_-_Codigo_fuente\Clase5\Clase4\Controllers\ProductoController.cs:43
   lambda_method(Closure , ControllerBase , Object[] ) +180
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +211
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9657896
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155