需要将原始值与当前值进行比较,以便在保存更改之前对对象进行一些更新。如何获取对象的原始值?以下不起作用:
public ActionResult Edit(int id = 0)
{
Project project = db.Projects.Find(id);
...
db.Projects.Attach(project); // ATTACH here
...
}
[HttpPost]
public ActionResult Edit(Project project)
{
if (ModelState.IsValid)
{
db.Entry(project).State = EntityState.Modified; // The STATE was DETACHED here...
...
}
这是配置问题,还是我错过了什么?提前感谢您的帮助!