Q:

NHibernate - paging - retrieving item either side of the current item result

I am implementing paging of a product detail page. The way this works is by passing the search criteria and filter on the query string, and when the product detail page loads, the same criteria and filter is applied and it determines the next and previous product to display.
I am using NHibernate for my ORM. What I'd like to do rather than loop through each product returned that matches the criteria to work out the previous and next product is basically say for product id with these criteria, give me the previous and next product.
Any ideas on how to implement?

A:

Clone the criteria for current product and add restrictions:
For next product: sortCoumn > currentProductsValue, sort order asc
For previous: sortCoumn < currentProductsValue, sort order desc
For both prev and next add SetMaxResults(1).

