I am trying to attach a LINQ entity to the data context after I receive it from a form POST. However, all I get is the following exception:
An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.
I have also tried attaching the original row, like so:
dataContext.People.Attach(person, originalPerson);
In this case, I get the following exception:
Object reference not set to an instance of an object.
Here's the code in my controller:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, Person person) {
var prevPerson = dataContext.People.Single(p => p.ID == id);
dataContext.People.Attach(person, prevPerson);
dataContext.SubmitChanges();
return Redirect("~/People/Index");
}
Any ideas on what I'm doing wrong here? I can post the entity code if needed.