我正在根據row_number進行排序和返回X行的查詢() 我正在使用NHibernate和MSSQL,並試圖使用CreateSQLQuery獲得分頁工作,我有這個查詢:用於分頁到HQL/ICriteria的NHibernate SQL查詢
select s.*
from(
select distinct release.[stop], survey.SurveyId, survey.Created, survey.CopyOfId, survey.DesignTemplateId, survey.UserId, survey.Template, [Row] = Row_Number() over (order by survey.[SurveyId])
from Survey as survey
inner join Release as release on release.SurveyId = survey.SurveyId
group by survey.SurveyId
, survey.Created
, survey.CopyOfId
, survey.DesignTemplateId
, survey.UserId
, survey.Template
, release.[stop]
) as s
where s.[Row] >= 0 and s.[Row] <= 20
order by s.[stop]
沒有人知道如何使用HQL或ICriteria(甚至更好),而不是普通的SQL來得到這個工作嗎?原因是我想要一個兼容SQLite和MS SQL Server 2005的查詢,這樣我就可以使用.SetMaxResult()或.SetFirstResult()
在此先感謝!
你也可以在同一個使用多目標進行第二次查詢總數量往返,以獲得總頁數。 – jishi 2010-06-30 12:30:12
感謝您的回答,但我想知道這個查詢在HQL或ICriteria中的樣子。 – dbn2k 2010-06-30 12:48:27
同樣,您也可以在查詢對象上調用這些方法。 – 2010-06-30 13:57:04