mvc music store
I'm trying to do the mvc musicstore tutorial, And after part 6 when using the edit I'm getting this error:
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.
Any idea why this is the reason?
[HttpPost]
public ActionResult Edit(Album album)
{
if (ModelState.IsValid)
{
db.Entry(album).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
ViewBag.ArtistId = new Selec开发者_JAVA百科tList(db.Artists, "ArtistId", "Name", album.ArtistId);
return View(album);
}
it was scaffold
Make sure that you're calling SaveChanges
in-between any Inserts, Updates, or Deletes.
精彩评论