Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I'm using AutoSaveChanges = false on a custom UserStore implementation. Unfortunately, when I call multiple methods of UserManager which internally call "UpdateUserAsync(user)" I get a DbUpdateConcurrencyException. I took me a lot of time to figure out when this happens exactly. Is it possible that the UpdateUserAsync implementation attaches the same UserEntity multiple times? If so, can this be fixed please?
Expected Behavior
No DbUpdateConcurrencyException.
Steps To Reproduce
var userEntity = dbContext.Users.First();
await userManager.UpdateAsync(userEntity);
await userManager.RemoveAuthenticationTokenAsync(user, "provider", "tokenname");
await dbContext.SaveChangesAsync(cancellationToken);
Exceptions (if any)
Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded. See https://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ThrowAggregateUpdateConcurrencyExceptionAsync(RelationalDataReader reader, Int32 commandIndex, Int32 expectedRowsAffected, Int32 rowsAffected, CancellationToken cancellationToken)
.NET Version
8
Anything else?
No response