私はasp.netを試しています。私はSystem.Data.Entity.Infrastructure.DbUpdateConcurrencyException
で困惑しています。例外は、「削除」アクションメソッドで自分のデータベースへの変更を保存しようとする行で発生します。ここで私のasp.netデータベースから項目を削除する方法
は完全に正常に動作編集方法、のための私のコードです:
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");
}
そして、ここにはありません、私のdeleteメソッドのコードです!
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");
}
データベースのタイプを知って参考になる:dBaseのは、MySQL、SQLServerのは? – Velocibadgery
@Aaron SQL Server Expressをインストールしました – user2651804
可能なdup。 https://stackoverflow.com/questions/28660708/intermittent-system-data-entity-infrastructure-dbupdateconcurrencyexception –