inverse="true"

2009/6/5 Eric <[email protected]>

>
> Hi all,
>
> I have a parent/child relationship and find that, when I update child
> records, NHibernate is updating the ID for the previous child records
> in the DB to NULL and inserting new records for all of the children
> (even ones that did not change), but not deleting the now-orphaned
> child records.  Thoughts on how to get the orphans to be deleted?
>
>  <class name="InvoiceLibrary">
>    ...
>    <bag name="LineItemList" table="lineitems" cascade="all-delete-
> orphan">
>      <key column="InvoiceLibraryId"/>
>      <one-to-many
>        class="LineItem"/>
>    </bag>
>  </class>
>
>  <class name="LineItem" table="LineItems" lazy="false">
>    ...
>    <many-to-one lazy="false" name="Parent" column="InvoiceLibraryID"
> not-null="true"
>                 class="InvoiceLibrary"
>                 />
>  </class>
>
>
> The save method looks like this (InvoiceLibrary object is passed in)
>
> public void Save<T>(T item)
> {
>    using (ISession session = m_SessionFactory.OpenSession())
>    {
>        using (session.BeginTransaction())
>        {
>            session.SaveOrUpdate(item);
>            session.Transaction.Commit();
>        }
>    }
> }
>
>
> After my initial save, and then an update of two line items and
> another save, I end up with one line in the InvoiceLibrary table, two
> lines in the LineItems table with the original line item data and an
> InvoiceLibraryId of null, and two lines in the LineItems table with
> the updated line item data and an InvoiceLibraryId pointing to the
> correct InvoiceLibrary.
>
> Thanks!
>
>
>
>
>
>
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to