Diagnosing and Fixing NHibernate Lazy‑Loading N+1 Select Issues
Learn how to spot NHibernate lazy‑loading N+1 select problems, diagnose them with SQL logging, and apply fixes such as eager fetch, batch‑size, or subselect loading.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Learn how to spot NHibernate lazy‑loading N+1 select problems, diagnose them with SQL logging, and apply fixes such as eager fetch, batch‑size, or subselect loading.
When NHibernate’s second‑level cache isn’t working, performance suffers. This guide walks you through the most common symptoms, root causes, ordered checks, fixes, and when to seek help.
NHibernate's Take/Skip normally generates dialect-specific SQL for pagination, but when a collection is eagerly fetched (e.g., Fetch(p => p.Children) ), the query may fall back to in-memory pagination after loading the full result set. This makes the number of distinct entities returned less than the requested page size and leaves the total row count ambi
Learn how to safely use NHibernate’s built‑in Hashtable second‑level cache for read‑heavy workloads, what to monitor, where it can fail, and when to move to a distributed cache.
The goal is to select a second‑level cache concurrency strategy for mutable entities that provides acceptable consistency while maximizing concurrent reads and writes in NHibernate. The documented strategies—read‑only, nonstrict‑read‑write, read‑write, and transactional—offer different locking and expiration guarantees, but the framework leaves the choice be
When using NHibernate’s second‑level cache, developers often enable the query cache to avoid repeated database hits for the same HQL or Criteria queries. The query cache stores results keyed by query string and parameters, and it relies on timestamp information from the underlying tables to decide whether a cached result is still fresh. However, the second‑l
The goal is to decide whether NHibernate’s second‑level cache can be trusted to provide repeatable reads when multiple async ISession instances share the same session factory in a repeatable development or test environment. In NHibernate 5.3+ the async ISession uses FlushMode.Auto, which does not automatically clear the second‑level cache when another thread
When configuring NHibernate's second‑level cache, the goal is to guarantee that each entity (or collection) uses a distinct cache region so that eviction and expiration policies apply only to the intended data. If the region attribute is omitted in the <cache> mapping or the programmatic equivalent, NHibernate treats the region as the default region na
Goal: configure NHibernate integration tests to run against an in‑memory SQLite database so that no production credentials are required, while guaranteeing that any mistake in the connection string is caught before the test suite starts. Uncertainty: NHibernate reads the connection string from the configuration but does not open a physical connection until t