I had an error that I cant reproduce again, but is like a exception where my database tries delete an item:
Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: Database operation expected to affect 1 row(s) but actually affected 0 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, Int32, Int32) + 0x7f
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ConsumeResultSetWithoutPropagation(Int32, RelationalDataReader) + 0xbe
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.Consume(RelationalDataReader) + 0xa7
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection) + 0x174
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable
1, IRelationalConnection) + 0x11b at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList
1) + 0x65
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList
1) + 0x41 at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(DbContext, Boolean) + 0x145 at System.Func
3.Invoke(T1, T2) + 0x2f
at Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute
TState, TResult
+ 0x3d
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean) + 0xf4
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean) + 0x10b
at MyApp.AppRepository.Delete(Person) + 0x46
at MyApp.AppViewModel.<DeleteInvitation>d__262.MoveNext() + 0x17b
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x21
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x70
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x38
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x17
at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0xb
at MyApp.AppViewModel.<CancelRequestAction>d__504.MoveNext() + 0xdc
My method:
public void Delete(Person person)
_dbContext.Wait();
this._dbContext.Person.Remove(person);
this._dbContext.SaveChanges();
finally
_dbContext.Release();