I use NHibernate 1.2 RC1. And have a simple object holding a collection.
Say something like a Parent with Childeren. When I delete the parent sql is fired for every child. All I want is to delete all Childeren in one go when the parent is deleted.
mappings:
Info Class: (the parent..)
<class name="Basplus.Core.Poco.Info, BasPlus.Core" table="Infos">
<id name="Id" column="Id">
<generator class="native" />
</id>
<property name="Created" />
<property name="Validtill" />
<property name="Titel" />
<property name="Omschrijving" />
<bag name="Infoitems" cascade="all-delete-orphan" inverse="true">
<key column="InfoId" />
<one-to-many class="Basplus.Core.Poco.Infoitem, BasPlus.Core" />
</bag>
</class>
Infoitem Class (the children of Info)
<class name="Basplus.Core.Poco.Infoitem, BasPlus.Core" table="Infoitems">
<id name="Id" column="Id">
<generator class="native" />
</id>
<many-to-one name="Info" column="InfoId" not-null="true" />
<many-to-one name="Artikel" class="Basplus.Core.Poco.Artikel, BasPlus.Core">
<column name="ArtikelKey" length="6" />
<column name="DistributeurId" />
</many-to-one>
</class>
Sql fired:
SELECT infoitems0_.InfoId as InfoId__1_, infoitems0_.Id as Id1_, infoitems0_.Id as Id6_0_, infoitems0_.InfoId as InfoId6_0_, infoitems0_.ArtikelKey as ArtikelKey6_0_, infoitems0_.DistributeurId as Distribu4_6_0_ FROM basplus.dbo.Infoitems infoitems0_ WHERE infoitems0_.InfoId=@p0; @p0 = '2935'
DELETE FROM basplus.dbo.Infoitems WHERE Id = @p0; @p0 = '316891'
DELETE FROM basplus.dbo.Infoitems WHERE Id = @p0; @p0 = '316892'
DELETE FROM basplus.dbo.Infoitems WHERE Id = @p0; @p0 = '316893'
....
....
DELETE FROM basplus.dbo.Infos WHERE Id = @p0; @p0 = '2935'
So as you can see a lot of (in my eyes) useless Sql is fired. Is there a better way to do this?
|