I try to save an edited Entity Framework entity ApplyPropertyChanges, and get an exception:
“The ObjectStateManager does not
contain an ObjectStateEntry with a
reference to an object of type
‘MvcApplication1.Models.Product’.”} System.Exception
{System.InvalidOperationException}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Product productToEdit) //all properties of Product are valid
{
try
{
productsDBEntities.ApplyPropertyChanges("ProductSet", productToEdit); //exception here
entities.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
Any idea would be very much appreciated!
Thanks!
You must first load
Productfrom database if you want to useApplyPropertyChanges:Or you can use another approach:
Btw. are you using .NET 3.5?
ApplyPropertyChangesis obsolete in .NET 4.0.