<bag name="Children" cascade="all" inverse="true">
<key column="parentId" on-delete="cascade"/>
<one-to-many class="Child"/>
</bag>

2009/5/14 MAMMON <[email protected]>

>
> So is there a way to clear all of the child elements in one shot,
> without deleting the parent?
>
> On May 14, 12:39 pm, Fabio Maulo <[email protected]> wrote:
> > the cascade is wrong.The cascade mean : what should do NH in case you are
> > doing something with the collection owner ?
> >
> > In your case you are saying to NH that you are interested in cascade only
> > when you are deleting the parent, all other actions (as update in your
> > example) will be ignored.
> >
> > The cascade="save-update" in the child has no sense.
> >
> > 2009/5/14 MAMMON <[email protected]>
> >
> >
> >
> >
> >
> > > Typical parent/child many-to-one relationship.  I want to be able to
> > > delete all children of a parent, but not the parent.  Also, I'd like
> > > to see a single DELETE statement against the child table, using the FK
> > > (the PK value of the parent table), rather than individual statements
> > > on the child table using the PKs of each child row.
> >
> > > Parent class:
> >
> > >                <bag name="Children" inverse="true" lazy="true"
> > > cascade="delete">
> > >                        <key column="ParentID" />
> > >                        <one-to-many class="Child" />
> > >                </bag>
> >
> > > Child class:
> >
> > >                <many-to-one name="Parent" column="ParentID"
> > > cascade="save-update"
> > > not-null="true" />
> >
> > > In the parent class, Children is declared as an IList<Child>.  CRUD
> > > operations appear to be working correctly, except in the case of
> > > deleting the entire child collection.  Here's what I'm trying.
> >
> > > Parent p = sess.Get<Parent>(1);
> > > p.Children.Clear();
> > > sess.Update(p);
> > > sess.Transaction.Commit();
> >
> > > This doesn't cause anything to be deleted.  If I do it this way:
> >
> > > foreach(Child c in p.Children)
> > >    sess.Delete(c);
> > > sess.Transaction.Commit();
> >
> > > Then the correct rows are deleted, but 1 at a time.  I want to see
> > > this instead:
> >
> > > DELETE from Child WHERE ParentID = (the parent's ID)
> >
> > > I tried to search in past posts here, and it seems that calling
> > > parent.Children.Clear() should work, but I'm not having any luck.
> >
> > > Help?
> >
> > --
> > Fabio Maulo
> >
>


-- 
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