When applying Paging (using SetFirstResult
and SetMaxResults
) to an ActiveRecord
SqlQuery
, with nHibernate 2.1.1 GA and ActiveRecord 2.0.1 the following sql is generated:
SELECT
TOP 40
FROM
(, ROW_NUMBER() OVER(ORDER BY account.Name, account.State) as __hibernate_sort_row
select account.Name
<rest of query>
) as query
WHERE query.__hibernate_sort_row > 40
ORDER BY query.__hibernate_sort_row
This errors and moreover doesn't run in sql... whereas it should be
SELECT TOP 40 *
FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY account.Name, account.State) as __hibernate_sort_row
,select account.Name
<rest of query>
) as query
WHERE query.__hibernate_sort_row > 40
ORDER BY query.__hibernate_sort_row
The odd things are :
- The query without paging works fine
- With paging, page 1 works fine (i.e. first result = 0, maxresult = 40)
- Exactly the same approach works fine for
HqlQuery
, onlySqlQuery
affected.
This applies to MS2005Dialect and MS2008Dialect...
Anyone know my stupid issue ?