views:

42

answers:

0

I have the following code in my repository. I use it for a product details page.

public Product GetBySlug(string slug)
{
    return session.CreateCriteria(typeof(Product))
        .SetFetchMode("CrossSell", FetchMode.Eager)
        .Add(Expression.Eq("Slug", slug))
        .UniqueResult<Product>();
}

This query currently gets one product and its related cross sell products. The domain entity looks like:

public class Product
{
    public virtual Guid Id { get; set; }
    public virtual int DisplayOrder { get; set; }
    public virtual string Slug { get; set; }
    public virtual IList<Product> CrossSell { get; set; }
}

I now would like to add next/previous product functionality to this page. In order to do that I need to fetch the previous and next product (or just the slug for the next/previous product which is enough to build both links) based on DisplayOrder. Ofcourse, I want to do this using one database transaction. What would be the proper way of doing this?

Thanks