Alright I have a parent and a child for the sake of discussion:
Parent-
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Blah.BizEntities"
namespace="Blah.BizEntities"
default-lazy="false">
<class name="Blah.BizEntities.Parent" table="core.Parent">
<id name="Id" column="ParentId" type="int" unsaved-value="0">
<generator class="identity" />
</id>
<bag name="Children" table="core.Child" cascade="all-delete-
orphan" inverse="true">
<key column="ParentId" />
<one-to-many class="Child"/>
</bag>
</class>
</hibernate-mapping>
And a child-
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Blah.BizEntities"
namespace="Blah.BizEntities"
default-lazy="false">
<class name="Blah.BizEntities.Child" table="core.Child">
<id name="Id" column="ChildId" type="int" unsaved-value="0">
<generator class="identity" />
</id>
<many-to-one name="Parent" class="Parent" column="ParentId" not-
null="true"/>
</class>
</hibernate-mapping>
The parent has an IList of Children, and the Child has an attribute of
the Parent.
So I create a few of each, then I delete the Parent's - the SQL
generated is like this:
NHibernate: DELETE FROM core.Parent WHERE ParentId = @p0; @p0 =
'8732241'
NHibernate: DELETE FROM core.Child WHERE ChildId = @p0; @p0 = '773083'
NHibernate: DELETE FROM core.Child WHERE ChildId = @p0; @p0 =
'773084'
NHibernate: DELETE FROM core.Child WHERE ChildId = @p0; @p0 =
'773085'
NHibernate: DELETE FROM core.Parent WHERE ParentId = @p0; @p0 =
'8732239'
NHibernate: DELETE FROM core.Child WHERE ChildId = @p0; @p0 =
'773080'
NHibernate: DELETE FROM core.Child WHERE ChildId = @p0; @p0 =
'773081'
NHibernate: DELETE FROM core.Child WHERE ChildId = @p0; @p0 =
'773082'
Wouldn't it be more efficient to delete the Children using the Parent
ID?
IE - DELETE FROM core.Child WHERE ParentId = X
Instead of-
DELETE FROM core.Child WHERE ChildId = X
DELETE FROM core.Child WHERE ChildId = Y
DELETE FROM core.Child WHERE ChildId = Z
If anyone knows how to convince nhibernate to do this I'd appreciate
some help.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---