我想在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
我试过但没有工作 –