NHibernate SetFirstResult & SetMaxResults Problems

I am using nHibernate and trying to implement some paging. If I run this code

IList list = session.CreateQuery("FROM Author").List();

it returns 8 records. If I run this code though

IList list = session.CreateQuery("FROM Author")
    .SetFirstResult(1).SetMaxResults(5).List();

it returns 0 records. When I look at the generated SQL, I don’t see that there is swap logic.

What are the most likely mistakes with this?

+3
source share
3 answers

I'm not sure about NHibernate, but in Java, the result index is based on 0. Try calling .SetFirstResult (0) instead of .SetFirstResult (1), otherwise, if there is only one row, it will return 0 results. It looks like you have 8 rows, so I don’t know why you won’t get any results anyway.

+3

, , , 0 .

SQL, MSSQL Server LIMIT OFFSET, . (n.b. , SQL Server 2005 , LIMIT OFFSET). , SQL 2000 , , .

, , , . , , . -, SetFirstResult/SetMaxResults .

+1

, Dialect Connection Provider web.config app.config

  <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
  <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
  <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
0

Source: https://habr.com/ru/post/1704870/


All Articles