ASP.Net Core Update Entity Hatası

Caulfield

Kilopat
Katılım
19 Ocak 2018
Mesajlar
864
Çözümler
3
Daha fazla  
Cinsiyet
Erkek
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:
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.
 
Son düzenleme:
Uyarı! Bu konu 6 yıl önce açıldı.
Muhtemelen daha fazla tartışma gerekli değildir ki bu durumda yeni bir konu başlatmayı öneririz. Eğer yine de cevabınızın gerekli olduğunu düşünüyorsanız buna rağmen cevap verebilirsiniz.

Technopat Haberler

Geri
Yukarı