1

During a save using a scaffolded MVC Controller I want to get the properties changed.

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();
}

I've attempted to use GetModifiedProperties from here Getting all changes made to an object in the Entity Framework

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

But VS tells me db "Does not contain a definition for ObjectStateManager". How do I get the changed fields from "quote"

1
  • Try using var myObjectState = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry([object name]). Let me know if it works. Commented Jun 16, 2017 at 1:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.