Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've no idea why the other two answers are so popular! </p> <p>I believe you were right in assuming the ORM framework should handle it - after all, that is what it promises to deliver. Otherwise your domain model gets corrupted by persistence concerns. NHibernate manages this happily if you setup the cascade settings correctly. In Entity Framework it is also possible, they just expect you to follow better standards when setting up your database model, especially when they have to infer what cascading should be done:</p> <p>You have to <a href="https://stackoverflow.com/questions/11033348/is-it-possible-to-remove-child-from-collection-and-resolve-issues-on-savechanges">define the parent - child relationship</a> correctly by using an "<a href="https://stackoverflow.com/questions/762937/whats-the-difference-between-identifying-and-non-identifying-relationships?lq=1">identifying relationship</a>".</p> <p>If you do this, Entity Framework knows the child object is <em>identified</em> by the parent, and therefore it must be a "cascade-delete-orphans" situation.</p> <p>Other than the above, you <strong>might</strong> need to (from NHibernate experience)</p> <pre><code>thisParent.ChildItems.Clear(); thisParent.ChildItems.AddRange(modifiedParent.ChildItems); </code></pre> <p>instead of replacing the list entirely. </p> <p><strong>UPDATE</strong></p> <p>@Slauma's comment reminded me that detached entities are another part of the overall problem. To solve that, you can take the approach of using a custom model binder that constructs your models by attempting to load it from the context. <a href="http://lostechies.com/jimmybogard/2011/07/07/intelligent-model-binding-with-model-binder-providers/" rel="nofollow noreferrer">This blog post</a> shows an example of what I mean.</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