NHibernate QueryOver API ↔ SQL Server Pagination: ensuring deterministic paging with .OrderBy()
0 reputation · 18 Mar 2020, 20:54 UTC
NHibernate QueryOver API ↔ SQL Server Pagination
When implementing server‑side paging with NHibernate’s QueryOver, the typical pattern is .OrderBy() followed by .Skip(n) and .Take(m). The goal is to retrieve page n of a stable result set without duplicates or gaps. The constraints are that the underlying SQL dialect may translate these calls into different constructs (LIMIT/OFFSET, TOP/FETCH, or ROW_NUMBER), and that a missing or unstable .OrderBy() can lead to non‑deterministic results. The uncertainty lies in whether NHibernate enforces a deterministic order when the same .OrderBy() expression is used across different database back‑ends, and how large .Skip() values affect performance and correctness on each dialect.
Specific questions:
- Does NHibernate guarantee that a given
.OrderBy()expression yields a stable ordering across all supported SQL dialects? - Are there documented performance regressions when using large
.Skip()values on PostgreSQL or Oracle? - What best practices exist for combining
.OrderBy()with.Skip()and.Take()to avoid duplicate or missing rows in paging scenarios?