ROW_NUMBER() and nhibernate - finding an item's page

前端 未结 3 899
旧巷少年郎
旧巷少年郎 2021-01-01 04:54

given a query in the form of an ICriteria object, I would like to use NHibernate (by means of a projection?) to find an element\'s order, in a manner equivalent to using

3条回答
  •  感动是毒
    2021-01-01 05:34

    ICriteria has this 2 functions:

     SetFirstResult()
    

    and

     SetMaxResults()
    

    which transform your SQL statement into using ROW_NUMBER (in sql server) or limit in MySql.

    So if you want 25 records on the third page you could use:

     .SetFirstResult(2*25) 
     .SetMaxResults(25)
    

提交回复
热议问题