1
I have a method that inserts several data from an excel spreadsheet into the database, but there are some data, such as email, password, or concurrencyStamp (set as NULL), so I can’t change users' data through the code.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> RegisterUserCreated(ApplicationUser user)
{
if (ModelState.IsValid)
{
user.UserName = user.Email;
user.NormalizedUserName = user.Email.ToTitleCase();
user.NormalizedEmail = user.Email.ToTitleCase();
if (user.Id_Matricula != null) user.Id = (int) user.Id_Matricula;
user.Departamento = _context.TbDepartamentos.Find(user.Id_Departamento);
var password = new PasswordHasher<ApplicationUser>();
var passwordHash = password.HashPassword(user, "Senha");
user.PasswordHash = passwordHash;
user.ConcurrencyStamp = await _userManager.GenerateConcurrencyStampAsync(user);
await _userManager.UpdateSecurityStampAsync(user);
_context.ApplicationUsers.Update(user);
_context.SaveChanges();
}
}
Error
An unhandled Exception occurred while Processing the request.
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. Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.Throwaggregateupdateconcurrencyexception(int commandIndex, int expectedRowsAffected, int rowsAffected)
It’s really ASP.NET Core?
– Jéf Bueno
Yes, . net core at least
– Weslley Rocha
Ah, okay. Just checking in.
– Jéf Bueno