我想在ASP.Net MVC更新單場5我得到錯誤:在ASP.Net更新單場MVC 5
我的代碼:
MyJobs.PublishStatus = 1;
db.MyJobContext.Attach(MyJobs);
db.Entry(MyJobs).Property(x => x.PublishStatus).IsModified = true;
//db.Configuration.ValidateOnSaveEnabled = false;
db.SaveChanges();
我得到波紋管錯誤:
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.
沒有關於此錯誤的職位,但我無法弄清楚: Entity Framework: "Store update, insert, or delete statement affected an unexpected number of rows (0)."
和在asp.net MVC更新單場:How to update only one field using Entity Framework?
'MyJobs.PublishStatus = 1;'如果'MyJobs'來自LINQ結果集,可能已經更新'PublishStatus',這樣當執行Attach時,就不會再有行被更新。 –
如果您將'ValidateOnSaveEnabled'設置爲false,則它將起作用。我可以看到你的代碼你已經有了這一行,你爲什麼評論它? – Munzer
我試過但沒有工作 –