-->
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.  [ 11 posts ] 
Author Message
 Post subject: Paging Query results
PostPosted: Tue Jul 12, 2005 3:28 pm 
Is it possible to implement paging type queries with NHibernate?

I'd like to implement custom paging within a DataGrid that is bound to a very large resultset and wish to cut down the rows returned by NHibernate. e.g. Some form of query that can restrict the result set to rows 130000 to 130050?


Top
  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 3:45 pm 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
Yes, the IQuery interface has SetFirstResult and SetMaxResults methods. On SQL Server this isn't quite optimal (yet) because the all records are queried and then filtered. With most other databases, some SQL construct is used to filter the results (LIMIT, ROWNUM) and that's far more efficient.

_________________
Cuyahoga


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 8:00 am 
Thanks. Tried it and it worked though a pity it isn't even quicker on SQL Server...


Top
  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 9:17 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Quote:
Thanks. Tried it and it worked though a pity it isn't even quicker on SQL Server...


...and it won't be either. Unfortunately that's a limitation of SQL Server 2000 and below - the only way to DB side paging is through stored procedures. NHibernate does it's paging by getting the entire match set but only instantiating the objects for the page you want.

Can't speak for the next version of SQL Server though...[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 10:31 am 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
Quote:
Can't speak for the next version of SQL Server though...


SQL Server 2005 has a rownum construct that will make db-paging possible.

_________________
Cuyahoga


Top
 Profile  
 
 Post subject: Paging Query results
PostPosted: Fri Nov 11, 2005 12:43 pm 
We've implemented inherited mssql dialect supporting paging through triple sorted subqueries. It performs quite well as first pages of the result are requested.

If anybody is interested, I can provide the source code of the dialect.


Top
  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 2:56 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
urmorae, could you please post your code?


Top
 Profile  
 
 Post subject: Code
PostPosted: Fri Nov 11, 2005 6:58 pm 
Newbie

Joined: Fri Sep 09, 2005 2:00 am
Posts: 9
Here it is:

http://urmo.mindworks.ee/MsSql2000ExtendedDialect.cs


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 10:07 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Server-side paging can be done reasonably efficiently in SQL 2000 using the following pattern:

SELECT * FROM table
WHERE primary key IN
(SELECT TOP page_size primary_key FROM table
WHERE primary_key NOT IN
(SELECT TOP page_size * (page_number - 1) primary_key FROM table
WHERE filter_conditions
ORDER BY sort_field)
AND filter_criteria
ORDER BY sort_field)
ORDER BY sort_field

Full details can be found here:

http://rosca.net/writing/articles/serverside_paging.asp

We have used this to great effect in our application and it would be nice if NHibernate had this built into the SQL dialect.

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 1:01 pm 
Newbie

Joined: Fri Oct 28, 2005 8:23 pm
Posts: 12
Urmo, Can you post an example of the paging in action with the datagrid if you have one handy.

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 3:09 am 
Unfortunately I don't have time to extract any examples. However, introduction to asp.net (quickstart) has probably one. So you have to take this bold step and explore it yourself.


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.