如何刪除項目我想了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");
}
這裏是不爲我的刪除方法的代碼!
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");
}
這將有助於瞭解數據庫類型:MySQL,SQLSERVER,質數據庫? – Velocibadgery
@Aaron我安裝了SQL Server Express的 – user2651804
可能DUP。 https://stackoverflow.com/questions/28660708/intermittent-system-data-entity-infrastructure-dbupdateconcurrencyexception –