nHibernate version:
1.2.1
Name and version of the database you are using:
MS SQL 2005
Hi all!!! I have a problem using the paging functionality of nHibernate.
I have a Table called "User" which contains about 100 000 records. My intention is now to always load for example 100 records each (paging functionality).
The Code I use for my C# application looks like this, where @index is the first result I want to receive and @count is the number of results.
Code:
return _util.CurrentSession.CreateCriteria(typeof(User)).SetFirstResult(index).SetMaxResults(count).List<User>();
When I execute to code with the parameters @index=99742 and @count=10, the code which i can see in my sql profiler is:
The generated SQL (show_sql=true):Code:
SELECT top 99752 this_.recid as recid0_0_, this_.firstname as firstname0_0_, this_.lastname as lastname0_0_, this_.email as email0_0_, this_.address as address0_0_, this_.zip as
zip0_0_, this_.city as city0_0_, this_.telephone as telephone0_0_ FROM users this_
What does this mean: I get 99752 records from my database (at least nhibernate gets all of them, in the code there are really only 10 records). Fetching 99752 records takes a very long time - and that's the problem. It would be much better to optimize the query so that the sql server only returns 10 records. Could anyone please give me some help how i could implement this....
Thanks!!
Best Regard
tredert