views:

24

answers:

1

I notice that some queries created by NHibernate are executed as batches whereas others are not. When I profile my database using Sql Server Profiler, the event type for these queries is listed as 'SQL:BatchStarting' followed by 'SQL:BatchCompleted', rather than simply RPC:Completed.

Is there any reason why some statements are run as batches and some not?

How does NHibernate decide which queries should be executed as batches?

It seems to execute a lot of single queries as batches - why would this be?

A: 

When inserting multiple items of the same type nhibernate will do this in batches determined from the batch size setting, this can be actually hard to detect in SQL Profiler as they appear to come as seperate RPC calls but are in fact sent to the server in one call.

The best way to see what is being batched is to use NHProf.

Here is blogpost that describes more about batching in NHibernate and how to profile what is going on: http://www.codinginstinct.com/2009/08/profiling-nhibernate-batching.html

Torkel