This code cannot actually save the changes:
// // POST: /SomeType/Edit/5 [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(Guid id, SomeType Model) { db.AttachTo(Model.GetType().Name, Model); db.ApplyPropertyChanges(Model.EntityKey.EntitySetName, Model); db.SaveChanges(); return RedirectToAction("Index"); }
ASP.NET MVC creates a Model object as an EntityObject unit type with an EntityState value of Individual .
After using the AttachTo method, its EntityState becomes Unchanged .
MSDN when attaching objects (Entity Framework)
Objects are bound to the object context in the Unchanged state.
Due to its state. No change. The ApplyPropertyChanges method does nothing.
I want the Change state to be instead.
MSDN in EntityState enumeration
Separately
An object exists but is not tracked by the Object Services object. The entity is in this state immediately after its creation and before it is added to the object context. The entity is also in this after it has been removed from the context, causing the method to break off or if it is loaded using NoTrackingMergeOption.
Without changes
The object has not been modified since it was loaded in context or since the last that the SaveChanges method is called.
Modified
The object was modified, but the SaveChanges method was not called.
I cannot explicitly set the EntityObject EntityState property to Modified . It is read-only.
Is it impossible to have strongly typed MVC controllers with EntityObjects?
Zack Peterson May 22 '09 at 20:04 2009-05-22 20:04
source share