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.
Yalçın Mete
80
Reputation points
Hi
If you allow, I would like to ask a question.
I want to replace the data I brought with the "public async Task<IActionResult> WriterEditProfile()" method with the "public IActionResult WriterEditProfile(AppUser p)" method.
"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."
I get an error.
Why does this occur? Is it because one method is "async" and the other method is not "async" that I get this error?
[HttpGet]
public async Task<IActionResult> WriterEditProfile()
{
var values = await _userManager.FindByNameAsync(User.Identity.Name);
return View(values);
}
[HttpPost]
public IActionResult WriterEditProfile(AppUser p)
{
UserManager userManager = new UserManager(new EfUserRepository());
userManager.TUpdate(p);
return RedirectToAction("Index","Dashboard");
}
public class UserManager : IUserService
{
IUserDal _userDal;
public void TUpdate(AppUser t)
{
_userDal.Update(t);
}
}
public class EfUserRepository : GenericRepository<AppUser> , IUserDal
{
}
public class GenericRepository<T> : IGenericDal<T> where T : class
{
public void Update(T t)
{
using var c = new Context();
c.Update(t);
c.SaveChanges();
}
}
Thanks
Sign in to answer