Eu tenho um metodo que insere varios dados de uma planilha do excel no banco de dados, mas não existem alguns dados, como por exemplo email, senha, ou concurrencyStamp (setados como NULL), então não consigo alterar os dados dos usuarios por meio do código.
[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();
}
}
Erro
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)