Hi All
I have a problem with seperate sql queries being generated for every item in a child collection when selecting the Parent.
I have a Parent object with an IList collection of Child objects.
If I run the following code using linq to nhibernate: IList parents = _repository.ToList();
I get the sql statements like the following:
SELECT * FROM Parent
SELECT * FROM Child WHERE ParentId = 1
SELECT * FROM Child WHERE ParentId = 2
SELECT * FROM Child WHERE ParentId = 3
SELECT * FROM Child WHERE ParentId = 4
etc etc
This is obviously extremely inefficient and assume it must be something to do with the mapping files?
Below is the mapping for the Child collection:
<bag name="Children" lazy="false" table="Child" cascade="all-delete-orphan">
<key column="ParentId"/>
<one-to-many class="Child" />
</bag>
Trust this is a newbie mistake somewhere.
Any help greatly appreciate.
S