0

I have seen the related question here:

An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key

But, I have not already loaded my entity (UserView.Employee) from the context anywhere, as you can see in the code snippet below.

public ActionResult EditEmployee(UserViewDetailsModel UserView)
        {
            UserView.Employee.Contact = db.Contacts.Find(UserView.Employee.Contact.ContactID);
            UserView.Employee.Manager = db.Employees.Find(UserView.ManagerID);
            db.Entry(UserView.Employee).State = EntityState.Modified;
            db.SaveChanges();

            return RedirectToAction("Index");
        }

Please tell me, how can I save the changes in this case ?

Community
  • 1
  • 1
teenup
  • 6,969
  • 11
  • 60
  • 108

1 Answers1

0

I don't have VS to hand to test this out but can you try something like:

db.Entry(UserView.Employee).CurrentValues.SetValues(EntityState.Modified);
Seany84
  • 5,284
  • 5
  • 40
  • 63