İçeriğe geç
ShiftDelete.Net
Haber ara/ SDN'ye SorGiriş
Haber Akışı SDNTV İnceleme Forum Yapay Zeka Akıllı Telefon Elektrikli Otomobil Oyun ShiftDelete.Net Global Teknoloji Haberleri Mobil Otomobil Donanım Savunma Bilim Sosyal Medya İnternet Giyilebilir Teknoloji Rehber Ürünler Son dakika Yazarlar
  1. Ana sayfa
  2. Topluluk
  3. Yazılım
  4. Diğer Yazılım Konuları
Diğer Yazılım Konuları

ASP.Net Core Update Entity Hatası

barann48804.03.20200 cevap1.002 görüntüleme
2018'den beri174 mesaj
#1
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:
[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.

Cevabını yaz

Cevap yazmak için giriş yap ya da üye ol. Eski forum kullanıcı adın ve parolanla girebilirsin.