Hello,
Please help me with the following issue
I want to set paging for my queries. So proceed in the following way:
Code:
IQuery query = m_Session.CreateQuery("select pr from Project as pr order by pr.Name asc");
query.SetMaxResults(pageSize);
query.SetFirstResult(pageIndex * pageSize);
return query.List();
The query
Code:
select pr from Project as pr order by pr.Name asc
executed as
Code:
IQuery query = m_Session.CreateQuery("select pr from Project as pr order by pr.Name asc");
return query.List();
[/code]
works fine. But when I try to set paging I get the following:
Quote:
Tp.UnitTests.SelectQueryTest.Paging : NHibernate.ADOException : Could not execute query
----> System.Data.SqlClient.SqlException : Column name 'project0_.Name' is invalid in the ORDER BY clause because it is not contained in an aggregate function and there is no GROUP BY clause.
I checked using SQL profiler and found that NHibernate forms the following query before forming the page select:
"select Count(*) as x0_0_ from Project project0_ order by [project0_].[Name] asc".
As you see - it is incorrect. Is it a bug or limitation to use NH paging only without order by? As I understand NH doesn't truncate the order by when it posts count select to know the total count of rows for forming the main page select query.
Please let me know if I am wrong or if you can help me.
Thanks.