I have the following sample which highlights a real problem I'm having.
Person -< Order -< OrderItem (mappings below)
When saving the I get 1 person record, 1 order record and 3 OrderItems with all relationships working (I Save person and everything cascade's correctly). I have the bidirectional relationship working with inverse on the appropriate collections/bags.
My problem is that when I Get( typeof(Person), id ), I'm getting the Person as expected, but with 3 Orders and each OrderItem replicated in each Order.
I've confirmed that this is caused by the fetch="join" in the Order.Items bag. If changed to Select it works just fine, but I'd like to avoid the extra roundtrip. Here are some snippets of the mappings:
Code:
<class name="Example.Model.Person, Example" table="Person">
<id name="Id" column="Id" type="Int64">
<generator class="identity"/>
</id>
<property name="Name" column="Name" type="String" not-null="true" />
<bag name="Orders" table="Order" fetch="join" cascade="all" inverse="true">
<key column="PersonId" />
<one-to-many class="Example.Model.Order, Example" />
</bag>
</class>
Code:
<class name="Example.Model.Order, Example" table="[Order]">
<id name="Id" column="Id" type="Int64">
<generator class="identity"/>
</id>
<many-to-one class="Example.Model.Person, Example" name="Person" column="PersonId" not-null="true" cascade="all" />
<property name="PlacedOn" column="PlacedOn" type="DateTime" not-null="true" />
<bag name="Items" table="OrderItem" fetch="join" cascade="all" inverse="true">
<key column="OrderId" />
<one-to-many class="Example.Model.OrderItem, Example" />
</bag>
</class>
Code:
<class name="Example.Model.OrderItem, Example" table="OrderItem">
<id name="Id" type="Int64">
<generator class="identity" />
</id>
<many-to-one class="Example.Model.Order, Example" name="Order" column="OrderId" not-null="true" cascade="all" />
<many-to-one class="Example.Model.Product, Example" name="Product" column="ProductId" cascade="all" />
<property name="Size" column="Size" type="String" not-null="false" />
<property name="Color" column="Color" type="String" not-null="false" />
</class>
I can provide a full sample VS project if it helps.