Question
Can Skip/Take reliably paginate many‑to‑many queries?
Rahul Byte
0 reputation · 18 Jul 2026, 23:48 UTC
94.5K views0
Goal
The objective is to retrieve a specific page—say the 10th page of 1,000 records—from a very large table that participates in a many‑to‑many relationship. The query must avoid loading the entire dataset into memory, prevent duplicate root entities, and maintain acceptable performance on SQL Server 2019 using NHibernate 6.
Constraints & Uncertainty
- Pagination is performed via
Skip()andTake()on anIQueryable. - The mapping uses
fetch="join"to eagerly load the related collection. - There is a risk of duplicate root entities when the join expands the result set before pagination is applied.
- StatelessSession is considered to reduce cache overhead, but its interaction with Skip/Take is unclear.
Specific Questions
- Does NHibernate correctly translate
Skip()andTake()into SQL when a fetch join is present, ensuring that pagination occurs after the join? - What alternative strategies (e.g., projections, row_number() subqueries, or StatelessSession) provide reliable pagination without duplicate roots?
- Is StatelessSession compatible with
IQueryableextensions likeSkip()andTake(), or does it require separate query construction?