[HttpPost]
public ActionResult Edit(Movie movie)
{
if (ModelState.IsValid)
{
db.Entry(movie).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(movie);
}
This action receives a movie model and updates it in the database.
But I can't figure out how.
The movie
object isn't attached to the db, so how does entity framework know which row in the db should be updaed?
I am sure that the Entry method has something to do with it, but I don't really know what this method does. I read that it provies information but I cannot understand how by just changing the State
of an entry it becomes attached and tracked by the DBContext
.