-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: DataGrid paging --- Page=@PageNo And PageSize=@PageSize
PostPosted: Thu Aug 04, 2005 10:30 pm 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Hi, I need to implement custom DataGrid paging: http://dotnetjunkies.com/Tutorial/EA868 ... F967F.dcik

Basically, idea is called a stored proc and retrieve only those records you need on "Current" page, thereby reducing processing and data transfer. The stored procedure takes as parameters "PageNumber" and "PageSize" to compute the records to return.

Normally, without stored proc:

o_session = SetupFESRCConnection(...)
criteria = o_session.CreateCriteria(GetType(mylib.to.Company))
...
conjunc = New NHibernate.Expression.Conjunction
criteria.Add(conjunc)
disjunc = New NHibernate.Expression.Disjunction
conjunc.Add(disjunc)
disjunc.Add(Expression.EqExpression.Eq("CompanyCode", companyCode))
company_list = criteria.List()

But how can I specify criteria "I just want page 3 data given page size = 10 records per page"? However, can I retrieve via stored procedure using NHibernate?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 6:33 am 
Newbie

Joined: Wed Aug 17, 2005 6:25 am
Posts: 4
use
criteria.SetFirstResult(recordtostartfrom)
.SetMaxResults(10)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 5:30 pm 
Beginner
Beginner

Joined: Wed Oct 05, 2005 5:35 am
Posts: 47
Location: France
Hmmm... And with Query API it would be something like:
Query.SetFirstResult(10)
Query.SetMaxResults(5)
... for 5 rows from 10th to 14th, right?

But it looks like it does a "select top" just by making 10+5: "select top 15 ..." So when you paged to the last page you get the whole set of your data again. Can't believe this is to get "5 rows from 10th to 14th"...
Am I missing something (again :) )?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 4:55 am 
Beginner
Beginner

Joined: Mon Oct 03, 2005 4:59 am
Posts: 26
Location: Cambridge, UK
I haven't inspected the SQL generated, but I've been using query.SetFirstResult() and query.SetMaxResult() quite happily for some time. It gets the right rows.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 16, 2005 9:07 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Hey Balagan,

The issue here is that some SQL servers don't support paging (notably MSSQL), so the NH developers have made the dialect for those DBs only retrieve the rows up to the last one you want and then NH simply instantiates the objects for the page you're after. It's a workaround, but it's due to flaws in the DB, not NH.

If you use a DB that supports paging you'll get the right SQL and only the rows you want.

Cheers,

Symon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.