Reputation: 3515
I've found very interesting tutorial for pagination using nhibernate http://blogs.planetcloud.co.uk/mygreatdiscovery/post/Simple-paging-with-ASPNET-MVC-and-NHibernate.aspx
How can these public PagedList<PSScript> GetPaged(int pageIndex, int pageSize)
query be rewriten for use without futures (main reason for these is that I should have working version for other databases, like firbird, etc.)
Or if you have some other interesting pagination tutorials to share, please do.
Thanks
Upvotes: 2
Views: 2264
Reputation: 174457
You can simply create the queries without Futures
. The only difference is that you will have two roundtrips to the database instead of one. I don't think that this will be a problem in your scenario.
Something like this should work:
using (ISession session = NHibernateHelper.OpenSession())
{
var rowCount = session.CreateCriteria<PSScript>()
.SetProjection(Projections.RowCount())
.UniqueResult<Int32>();
var results = session.CreateCriteria<PSScript>()
.SetFirstResult((pageIndex - 1) * pageSize)
.SetMaxResults(pageSize)
.ToList<PSScript>();
return new PagedList<PSScript>(results, pageSize, pageSize, rowCount);
}
Upvotes: 3