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 ?

2
  • are you doing select * in the sql query?
    – dotjoe
    Feb 4, 2010 at 20:32
  • no. All fields are nominated. I've also aliased them uniquely, it still produces junk sql. I'm adding manually now. Not ideal.
    – penderi
    Feb 5, 2010 at 11:57

2 Answers 2

0

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 ?

1
  • We're double selecting but that's our solution for now. Needs a retest with NH 3.0
    – penderi
    Jun 20, 2011 at 10:00
0

I used a work-around for it. Here its link. May be helpful to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.