tags:

views:

177

answers:

0

When performing a query with NHibernate does not seem to be respecting the batch-size if it is set to more than the results actually returned.

I am using the latest version of NHibernate 2.1.0.4000 and the GA of Linq to NHibernate. I have an object structure similar to the Order which has a collection of OrderLines. The OrderLines have been defined as a bag with the following xml:

<bag name="OrderLines" access="field.camelcase" table="MyDatabase.OrderLines" lazy="true"   batch-size="50">
    <key column="OrderId"/>
    <one-to-many class="OrderLine"/>
</bag>

If I query for Orders and get 50 results back it correctly selects all the OrderLines in a single query, but if I get less than 50 results back it does not seem to respect the defined batch size.

E.g. If I get 40 results back instead of 50 if performs 3 queries with a batch size of 25, 12 and 3

Which looks like it is trying to guess the correct batch size to use (ie it does 1/2 the batch size first, then 1/2 the remainder etc). I would expect it to perform a batch size of 50 all the time and if there are less then make the batch size as large as it can, in this case a batch size of 40.

How can I get NHibernate to respect the batch size I have defined in all cases?