数据库操作预计影响 1 行但实际影响 92085 行数据可能已被修改或删除
The database operation was expected to affect 1 row(s) but actually affected 92085 row(s) data may have been modified or deleted
我的 GraphQL .NET 服务器上有这段代码。
它应该做一个简单的更新查询。
注意delete,create,read是可以的
全部 上面评论的更新可能性是 全部 给我这个错误:
Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: The database operation was expected to affect 1 row(s), but actually affected 92085 row(s); data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ThrowAggregateUpdateConcurrencyException(Int32 commandIndex, Int32 expectedRowsAffected, Int32 rowsAffected)
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ConsumeResultSetWithoutPropagation(Int32 commandIndex, RelationalDataReader reader)
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.Consume(RelationalDataReader reader)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(StateManager stateManager, Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<>c.<SaveChanges>b__104_0(DbContext _, ValueTuple`2 t)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
at GlanumAppsApi.Controllers.TimeTrackingController.CreateTimeTracking(TimeTrackingModel timeTracking) in C:\Users\Edouard\RiderProjects\GlanumAppsApi\GlanumAppsApi\Controllers\TimeTrackingController.cs:line 62
我尝试了很多东西。
我尝试了并发令牌、时间戳和绝对可以存在于 Google.
上的 all
public TimeTrackingModel CreateTimeTracking(TimeTrackingModel timeTracking)
{
try
{
var ctx = _context();
if (timeTracking.Id > 0)
{
/*
var entry = ctx.TimeTrackings.Find(timeTracking.Id)!;
ctx.Entry(entry).CurrentValues.SetValues(timeTracking);
//ctx.TimeTrackings.Update(entry);
var test = ctx.ChangeTracker.ToDebugString();
ctx.SaveChanges();
*/
var entry = ctx.TimeTrackings.Find(timeTracking.Id)!;
entry.Commentaire = "ziofjzie";
// ctx.Entry(entry).CurrentValues.SetValues(timeTracking);
// ctx.TimeTrackings.Update(entry);
// ctx.Entry(entry).State = EntityState.Modified;
var test = ctx.ChangeTracker.ToDebugString();
ctx.SaveChanges();
/*
ctx.TimeTrackings.Attach(timeTracking);
ctx.TimeTrackings.Update(timeTracking);
var test = ctx.ChangeTracker.ToDebugString();
ctx.SaveChanges();
*/
}
else
{
ctx.TimeTrackings.Add(timeTracking);
ctx.SaveChanges();
}
return timeTracking;
}
catch
{
return new TimeTrackingModel();
}
}
在我的一个错误测试中,测试变量给了我这个结果:
TimeTrackingModel {Id: 92085} Modified
Id: 92085 PK
Chevauchement: <null> Modified
Commentaire: 'ziofjzie' Modified Originally 'test'
DateCreation: <null> Modified
DateModification: <null> Modified
DateSuppression: <null> Modified
Debut: '22/04/1978 06:00:00' Modified
EstDeductible: 'True' Modified
Fin: '22/04/1981 06:00:00' Modified
Id_Tache: 1 FK Modified
Id_Utilisateur: 5 FK Modified
Tache: <null>
Utilisateur: <null>
如您所见,entity framework 核心 6 为我提供了预期的正确更改,但仍然抛出该错误。
这是数据库条目:
Id Debut Fin DateCreation DateModification DateSuppression Id_Utilisateur Id_Tache Chevauchement Commentaire estDeductible
92086 1979-04-22 06:00:00.000 1982-04-22 06:00:00.000 NULL NULL NULL 5 1 _92085_ sdfsdfsdf 1
92085 1978-04-22 06:00:00.000 1981-04-22 06:00:00.000 NULL NULL NULL 5 1 _92086_ test 1
由@David Browne 解决 - Microsoft
我通过
关闭了触发器
DISABLE TRIGGER TimeTracking_OnInsertUpdateDelete on TimeTracking;
DISABLE TRIGGER TimeTracking_AspNet_SqlCacheNotification_Trigger on TimeTracking;
正在运行! :)
我的 GraphQL .NET 服务器上有这段代码。
它应该做一个简单的更新查询。
注意delete,create,read是可以的
全部 上面评论的更新可能性是 全部 给我这个错误:
Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: The database operation was expected to affect 1 row(s), but actually affected 92085 row(s); data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ThrowAggregateUpdateConcurrencyException(Int32 commandIndex, Int32 expectedRowsAffected, Int32 rowsAffected)
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ConsumeResultSetWithoutPropagation(Int32 commandIndex, RelationalDataReader reader)
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.Consume(RelationalDataReader reader)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(StateManager stateManager, Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<>c.<SaveChanges>b__104_0(DbContext _, ValueTuple`2 t)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
at GlanumAppsApi.Controllers.TimeTrackingController.CreateTimeTracking(TimeTrackingModel timeTracking) in C:\Users\Edouard\RiderProjects\GlanumAppsApi\GlanumAppsApi\Controllers\TimeTrackingController.cs:line 62
我尝试了很多东西。
我尝试了并发令牌、时间戳和绝对可以存在于 Google.
public TimeTrackingModel CreateTimeTracking(TimeTrackingModel timeTracking)
{
try
{
var ctx = _context();
if (timeTracking.Id > 0)
{
/*
var entry = ctx.TimeTrackings.Find(timeTracking.Id)!;
ctx.Entry(entry).CurrentValues.SetValues(timeTracking);
//ctx.TimeTrackings.Update(entry);
var test = ctx.ChangeTracker.ToDebugString();
ctx.SaveChanges();
*/
var entry = ctx.TimeTrackings.Find(timeTracking.Id)!;
entry.Commentaire = "ziofjzie";
// ctx.Entry(entry).CurrentValues.SetValues(timeTracking);
// ctx.TimeTrackings.Update(entry);
// ctx.Entry(entry).State = EntityState.Modified;
var test = ctx.ChangeTracker.ToDebugString();
ctx.SaveChanges();
/*
ctx.TimeTrackings.Attach(timeTracking);
ctx.TimeTrackings.Update(timeTracking);
var test = ctx.ChangeTracker.ToDebugString();
ctx.SaveChanges();
*/
}
else
{
ctx.TimeTrackings.Add(timeTracking);
ctx.SaveChanges();
}
return timeTracking;
}
catch
{
return new TimeTrackingModel();
}
}
在我的一个错误测试中,测试变量给了我这个结果:
TimeTrackingModel {Id: 92085} Modified
Id: 92085 PK
Chevauchement: <null> Modified
Commentaire: 'ziofjzie' Modified Originally 'test'
DateCreation: <null> Modified
DateModification: <null> Modified
DateSuppression: <null> Modified
Debut: '22/04/1978 06:00:00' Modified
EstDeductible: 'True' Modified
Fin: '22/04/1981 06:00:00' Modified
Id_Tache: 1 FK Modified
Id_Utilisateur: 5 FK Modified
Tache: <null>
Utilisateur: <null>
如您所见,entity framework 核心 6 为我提供了预期的正确更改,但仍然抛出该错误。
这是数据库条目:
Id Debut Fin DateCreation DateModification DateSuppression Id_Utilisateur Id_Tache Chevauchement Commentaire estDeductible
92086 1979-04-22 06:00:00.000 1982-04-22 06:00:00.000 NULL NULL NULL 5 1 _92085_ sdfsdfsdf 1
92085 1978-04-22 06:00:00.000 1981-04-22 06:00:00.000 NULL NULL NULL 5 1 _92086_ test 1
由@David Browne 解决 - Microsoft 我通过
关闭了触发器DISABLE TRIGGER TimeTracking_OnInsertUpdateDelete on TimeTracking;
DISABLE TRIGGER TimeTracking_AspNet_SqlCacheNotification_Trigger on TimeTracking;
正在运行! :)