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.  [ 4 posts ] 
Author Message
 Post subject: Paging query result with Nhibernate Criteria and Sql 2k
PostPosted: Fri Aug 08, 2008 4:10 am 
Newbie

Joined: Thu May 29, 2008 4:11 am
Posts: 8
Hi all,
can someone help me how to paging query result using Criteria and Sql 2K ( not SQL 2K5 ) ?
Can someone post a sample of doing it?
Thanks in advance,
Simone


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 6:23 am 
Newbie

Joined: Sat Apr 05, 2008 6:33 pm
Posts: 16
you could try this:

DetachedCriteria pagedQuery = DetachedCriteria.For<Entity>()
.SetMaxResults(pageSize)
.SetFirstResult(pageSize*pageIndex);

DetachedCriteria countQuery = DetachedCriteria.For<Entity>()
.SetProjection(Projections.Count());

var result = session.CreateMultiCritieria()
.Add(pagedQuery)
.Add(countQuery)
.List();

var items = result[0];
var count = (long)result[1];


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 10:42 am 
Newbie

Joined: Thu Aug 21, 2008 8:22 am
Posts: 5
are you sure with this ?

Because DetachedCriteria does'nt contain SetMaxResults / SetFirstResult Methods.

And There is not usage with CreateMultiCritieria


torkelo wrote:
you could try this:

DetachedCriteria pagedQuery = DetachedCriteria.For<Entity>()
.SetMaxResults(pageSize)
.SetFirstResult(pageSize*pageIndex);

DetachedCriteria countQuery = DetachedCriteria.For<Entity>()
.SetProjection(Projections.Count());

var result = session.CreateMultiCritieria()
.Add(pagedQuery)
.Add(countQuery)
.List();

var items = result[0];
var count = (long)result[1];


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 10:12 am 
Newbie

Joined: Fri Sep 09, 2005 2:00 am
Posts: 9
We use our own modified MS SQL 2000 dialect for this so that standard setmaxresult and setfirstresult work. Dialect makes use of triple sorting trick and works pretty well. If you like, I can make the source of the dialect downloadable.


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