Note that there are some explanatory texts on larger screens.

plurals
  1. POfluent nhibernate Cascade creates new records instead of updating them
    primarykey
    data
    text
    <p>So being new to n-hibernate and fluent n-hibernate for that matter, I'm having some confusion with mapping and cascading changes to child objects.</p> <p>I have a object that has several collections, when I create a new object it creates the child objects and inserts them into their respective tables. That's all fine and good. However, when I go to update the parent with changes in the child objects on the surface it appears to flow just they way I want it to. The kicker is that when looking into the db I see that instead of updating the child object record it has inserted new records and removed the association to the parent object from the original records instead of just updating them.</p> <p>To add additional explanation we are using AutoMapping and MappingOverrides. So here is a brief look at the code I'm working with.</p> <pre><code>public class ParentObjectOverride : IAutoMappingOverride&lt;ParentObject&gt; { public void Override(AutoMapping&lt;ParentObject&gt; mapping) { mapping.HasMany(x =&gt; x.Chid1).Cascade.SaveUpdate().Table("chid1Table"); mapping.HasMany(x =&gt; x.Child2).Cascade.SaveUpdate().Table("child2Table"); } } public class Child1Override : IAutoMappingOverride&lt;Child1&gt; { public void Override(AutoMapping&lt;Child1&gt; mapping) { mapping.References(x =&gt; x.ParentObject).Cascade.All(); } } public class Child2Override : IAutoMappingOverride&lt;Child2&gt; { public void Override(AutoMapping&lt;Child2&gt; mapping) { mapping.References(x =&gt; x.ParentObject).Cascade.All(); } } </code></pre> <p>There really isn't a case where the child objects are saved independantly of the ParentObject. I've tried cascade.all() as well as cascade.saveupdate() both produce the same results.</p> <p>I've read several posts about using AllDeleteOrphan, but I don't see why it shouldn't just update the child rows instead of making new rows and deleting the old ones. Maybe I just don't understand the mapping concept.</p> <p>Any assistance is appreciated</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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