0

In MvcMusicStore tutorial, the program is blocked by db.SaveChanges(); in Edit [post] Controller. The errors shows

An exception of type 'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' occurred in EntityFramework.dll but was not handled in user code Additional information: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.

The Edit [post] code is as followings:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album)
{
    if (ModelState.IsValid)
    {
        db.Entry(album).State = EntityState.Modified;
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
    ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
    return View(album);
}
adiga
  • 34,372
  • 9
  • 61
  • 83

1 Answers1

0

Looks at this link : Entity Framework: "Store update, insert, or delete statement affected an unexpected number of rows (0)."

Check your AlbumId is greater than 0 with a break point in your action Controller, may be you forget an hidden field in view.

If this solve your problem, please check the anwser and others will close subject for duplication, i can't to do it by myself.

GGO
  • 2,678
  • 4
  • 20
  • 42