带有实体框架的MVC5获取修改后的属性

时间:2017-06-15 16:10:47

标签: c# asp.net-mvc entity-framework

在使用scaffolded MVC Controller进行保存期间,我希望更改属性。

private myEntities db = new myEntities();

public ActionResult Edit()
if (ModelState.IsValid)
{
     tblQuote quote = db.Quotes
     .Include(a => a.Parts)
     .SingleOrDefault(x => x.QuoteID == 4);

     quote.Name = "NewName"

     db.Entry(quote).State = EntityState.Modified;

     db.SaveChanges();
}

我试图从这里使用GetModifiedProperties Getting all changes made to an object in the Entity Framework

var myObjectState=db.ObjectStateManager.GetObjectStateEntry(quote);

但VS告诉我db“不包含ObjectStateManager的定义”。如何从“quote”

获取更改的字段

0 个答案:

没有答案