Note that there are some explanatory texts on larger screens.

plurals
  1. POStrongly-Typed ASP.NET MVC with Entity Framework
    text
    copied!<p>This code fails to actually save any changes:</p> <pre><code>// // 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"); } </code></pre> <p>ASP.NET MVC creates the object Model as a Department type EntityObject with an EntityState value of <strong>Detached</strong>.</p> <p>After using the <em>AttachTo</em> method, its EntityState becomes <strong>Unchanged</strong>.</p> <p><a href="http://msdn.microsoft.com/en-us/library/bb896271.aspx" rel="nofollow noreferrer">MSDN on Attaching Objects (Entity Framework)</a></p> <blockquote> <p>Objects are attached to the object context in an <strong>Unchanged</strong> state.</p> </blockquote> <p>Because of its <strong>Unchanged</strong> state, the method <em>ApplyPropertyChanges</em> does nothing.</p> <p>I want it to instead have state <strong>Modified</strong>.</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.data.entitystate.aspx" rel="nofollow noreferrer">MSDN on EntityState Enumeration</a></p> <blockquote> <p><strong>Detached</strong><br> The object exists but it is not being tracked by Object Services. An entity is in this state immediately after it has been created and before it is added to the object context. An entity is also in this state after it has been removed from the context by calling the Detach method or if it is loaded using a NoTrackingMergeOption.</p> <p><strong>Unchanged</strong><br> The object has not been modified since it was loaded into the context or since the last time that the SaveChanges method was called.</p> <p><strong>Modified</strong><br> The object is changed but the SaveChanges method has not been called.</p> </blockquote> <p>I cannot explicitly set an EntityObject's EntityState property to <strong>Modified</strong>. It is read only.</p> <p>Is it just impossible to have strongly-typed MVC controllers with EntityObjects?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload