1.2 beta sql server 2000
Hi,
I started to experiment with the build-in paging function for my forum project and I was curios on how NHibernate does it.
I did
Code:
q.SetMaxResults(50);
//first page
q.SetFirstResult(0);
//second page
//q.SetFirstResult(50);
I noticed if I set paging to 50, for 1st page, it did select Top 50, but for 2nd page, it did select Top 100??
that doesn't seem right... I guess it's a not a big deal since I don't think my forum will grow beyound couple thousands of threads... but still doesn't seem to be the best way. (but i did do a test of 10,000 threads, all got done in 4 seconds. Used the .NET SqlDataReader as well, 4 seconds as well, so no performance hit as far as my requirements), but any advice on that? How do you do paging in your app?
Anyway, back to .setFirstResult(). To properly figure out paging, I have to know how many pages there is gonne be. How do you do that? I suppose I can do
Code:
if( (total records % pageSize)==0)
{
number_of_pages = total records / pageSize;
}
else{
number_of_pages = total records / pageSize + 1;
}
but then, how do I figure out the total records in one query without doing a seperate db call?
Here is my existing query
Code:
IQuery q = session.CreateQuery(
"select discussions.DiscussionID, discussions.DiscussionTitle, discussions.CreatedBy, count(comments) " +
"from JumptreeForum_Discussions as discussions " +
"left outer join discussions.Comments as comments " +
"where :categoryid in " +
"( " +
" select categories.CategoryID from discussions.Categories categories " +
" ) " +
"group by discussions.DiscussionID, discussions.DiscussionTitle, discussions.CreatedBy"
);
q.SetInt32("categoryid", Convert.ToInt32(categoryid));
q.SetMaxResults(50);
q.SetFirstResult(50*pageNumber); // how do i get pagenumber?
result = q.List();
Thanks.