Book Image

Learning NHibernate 4

Book Image

Learning NHibernate 4

Overview of this book

Table of Contents (18 chapters)
Learning NHibernate 4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Batching


Total execution time of a NHibernate query constitutes of three things:

  • Time it takes to send the query to remote database server

  • Time it takes to execute actual SQL on the database server

  • Time it takes to return the results to client, process the results on client, and hydrate the entities

Depending on what kind of queries you are writing, you may be spending a lot of time sending your queries to remote database server. In such a situation, you can batch multiple SQL statements together and send them to database server for execution in one roundtrip. Batching does not impact the time it takes to execute actual SQL on the server, but reduces the network time as you are doing a single database interaction against several you would have done in absence of batching. NHibernate offers different ways of batching queries that can be used in different scenarios.

As we discussed in the beginning, NHibernate queries can be generally divided into two buckets – read queries and write queries. For...