barann488
Asistan
- Katılım
- 20 Ocak 2018
- Mesajlar
- 174
- Reaksiyon puanı
- 16
- Puanları
- 18
- Yaş
- 29
Arkadaşlar User güncellemeye çalışırken şu hatayı alıyorum:
An unhandled exception occurred while processing the request.
InvalidOperationException: The instance of entity type 'AppUser' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.
Kod bloğum şu şekilde:
Not: Sosyal medya projesi yapıyorum. AppUser tablosundan 2 adet ForeignKey üretiyorum.
An unhandled exception occurred while processing the request.
InvalidOperationException: The instance of entity type 'AppUser' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.
Kod bloğum şu şekilde:
Kod:
[HttpPost]
public async Task<IActionResult> Edit(UserDTO model)
{
AppUser user = await _userManager.FindByNameAsync(User.Identity.Name);
if (ModelState.IsValid)
{
user = mapper.Map<AppUser>(model);
if (model.Password != null)
{
user.PasswordHash = _passwordHasher.HashPassword(user, model.Password);
}
IdentityResult result = await _userManager.UpdateAsync(user);
if (result.Succeeded)
{
uow.SaveChange();
await _signInManager.SignOutAsync();
return Redirect("/Account/Login");
}
else
{
foreach (var item in result.Errors)
{
ModelState.AddModelError("", item.Description);
}
}
}
return View(user);
}
Not: Sosyal medya projesi yapıyorum. AppUser tablosundan 2 adet ForeignKey üretiyorum.