views:

123

answers:

1

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, only SqlQuery affected.

This applies to MS2005Dialect and MS2008Dialect...

Anyone know my stupid issue ?

A: 

Well I've found this page Possible SQL Server bug which, contra to the title, suggests I'll need to write it in my sql. No problem just could have done without spending half a day trying.

Can anyone confirm this is definitely the case ?

ip