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?
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).
精彩评论