I'm trying out asp.net and I'm stumped by a System.Data.Entity.Infrastructure.DbUpdateConcurrencyException. The exception occurs on the line I try to save changes to my database in the 'Delete' action method.
Here is my code for the edit method, which works perfectly fine:
public ActionResult Edit(int id) { Movie movie = db.Movies.Find(id); if (movie == null) { return HttpNotFound(); } return View(movie); } [HttpPost] public ActionResult Edit(Movie movie) { db.Entry(movie).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } And here is the code for my delete method which does not!
public ActionResult Delete(int id) { Movie movie = db.Movies.Find(id); if (movie == null) { return HttpNotFound(); } return View(movie); } [HttpPost] public ActionResult Delete(Movie movie) { db.Movies.Attach(movie); db.Movies.Remove(movie); //db.Entry(movie).State = System.Data.Entity.EntityState.Deleted; //both the outcommented line above and the current method of marking for deletion result in the same exception on the line below. db.SaveChanges(); return RedirectToAction("Index"); }