Stop NHibernate N+1 selects with LINQ Fetch and FetchMany
Use NHibernate LINQ Fetch and FetchMany to load associations in one query instead of triggering a select for every row.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Use NHibernate LINQ Fetch and FetchMany to load associations in one query instead of triggering a select for every row.
Learn how to enable, configure, and verify NHibernate’s Second‑Level Cache, including provider setup, TTL settings, and common pitfalls for production use.
Learn how to enable NHibernate’s second‑level cache, pick a consistency strategy, and monitor its effectiveness with built‑in statistics.
Learn how to spot the NHibernate N+1 select problem in lazy‑loaded collections, diagnose it with SQL logging and session statistics, and apply batch‑size or fetch fixes.
A concise architecture note on NHibernate's second‑level cache: requirements, minimal design, trust boundaries, operational checks, failure modes, and when to redesign. Includes concrete SysCache2 configuration, query caching, and a diagnostic checklist.
StatelessSession cuts memory and CPU for large sequential inserts, but drops caching, lazy loading, and automatic dirty checking. This guide shows when it pays off, how to map, and the pitfalls that affect caching, events, and concurrency.
Decide when to use StatelessSession for high-volume inserts and when the full ISession is needed, with a comparison table, trade-offs, and a sample implementation.
LazyInitializationException means a proxy was touched after its ISession closed. Diagnose the lifetime-vs-access mismatch, then fix it with explicit fetches, DTO projections, or scoped initialization.
NHibernate Future Queries batch multiple reads into a single database round trip. This post shows the API, a concrete dashboard example, driver behavior differences, and the limits you'll hit with stateless sessions, parameter caps, and all-or-nothing error handling.