I'm using the entity framework code first approach for an ASP.NET MVC application. After editing a row when submitting for saving the change I'm getting the following error for the http post method:
An exception of type 'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' occurred in EntityFramework.dll but was not handled in user code.
This error is encountered at db.SaveChanges().
db.Entry<Project>(EditedProj).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
Main code:
[HttpGet]
public ActionResult Edit(int id)
{
using (var db = new ProjectContext())
{
return View(db.Projects.Find(id));
}
}
[HttpPost]
public ActionResult Edit(Project EditedProj)
{
using (var db = new ProjectContext())
{
db.Entry<Project>(EditedProj).State =
System.Data.Entity.EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Projects");
}
}
See Question&Answers more detail:os