Here are some general tips for optimizing queries with NHibernate:
Select only the properties you need; that is, avoid selecting the full entity when you don’t need it.
Avoid loading an entity when you only need its key (use ISession.Load<T> instead of ISession.Get<T>).
Use paging instead of retrieving all records at the same time; all querying APIs support it.
Fetch at query time all the references and collections that you will need.
Choose lazy and eager loading carefully, and choose an appropriate fetch mode. If you are certain that you need a child collection’s items each time you load a specific entity, mark this collection as not lazy and with fetch mode JOIN.
Resort to SQL queries when performance is crucial.
Optimizing Making Changes
Consider this:
Always use explicit transactions.
Use executable HQL for bulk updates and deletes.
Use batching and stateless sessions for insertions.
Evict unneeded entities from the session.
Mark entities that you never want to change as immutable so that the session does not waste time with them when tracking changes.
Use explicit flushing and, when flushing, also clear the session or evict unneeded entities.
In production, disable logging and statistics.
DISCLAIMER:
Web reader is currently in beta. Please report any issues through our support system. PDF and Kindle format files are also available for download.
Previous
Next
A
A
A
of
Build apps 2X faster
using Syncfusion Essential Studio® suite
1800+ high-performance UI components.
Includes popular controls such as Grid, Chart, Scheduler, and more.