Diagnosing and Fixing the N+1 Select Problem in NHibernate
A diagnostic guide to the N+1 select problem in NHibernate: recognize it in SQL logs, isolate the lazy-loading trigger, and fix it with batch-size, per-query eager fetching, or projections.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
A diagnostic guide to the N+1 select problem in NHibernate: recognize it in SQL logs, isolate the lazy-loading trigger, and fix it with batch-size, per-query eager fetching, or projections.
NHibernate's SetFirstResult and SetMaxResults keep paging in the database, but only with explicit ordering, a matching count query, and verified SQL.
Learn how to bypass the first‑level cache and leverage ADO.NET batching with NHibernate’s stateless session for fast inserts, updates, and deletes.
Learn how to use NHibernate IStatelessSession to handle bulk data operations without memory exhaustion, including configuration for ADO.NET batching and critical architectural trade-offs.
Map a version column, carry it across web requests, handle StaleObjectStateException with a bounded retry, and verify the UPDATE’s WHERE clause enforces the check.
Architecture note on configuring NHibernate’s second‑level cache for read‑heavy .NET applications, including required XML, provider selection, concurrency strategy nuances, monitoring, failure modes, and triggers for redesign.
Repeatedly loading the same reference data on every request wastes database round-trips. Here's how NHibernate's second-level cache with the SysCache2 provider fixes that — and where it falls down.
Learn how to turn on NHibernate’s second‑level cache, configure a provider, and verify hits in real code. Avoid common pitfalls and understand the limits of query and entity caching.
Choosing the right second‑level cache provider for NHibernate 5.x is critical for read‑heavy workloads. This guide compares SysCache, Redis, Memcached, and InMemory, explains trade‑offs, and walks through a concrete Redis implementation with validation steps.