Paul
Paul

Reputation: 12799

Reusable OrderBy with QueryOver in NHibernate problem

I have that code using ICritiria

public virtual IEnumerable<T> GetPagined(int __pageIndex, int __pageSize, string __order, bool __ascending, out int __total)
{
...
     var _results = Session.CreateCriteria(typeof(T))
         .AddOrder(new Order(__order, __ascending))
         .Future<T>();
...
}

I´m trying to convert that to QueryOver... The problem is with OrderBy... I did that:

if (__ascending)
      _query.OrderBy(x => x.Name).Asc();
else
      _query.OrderBy(x => x.Name).Desc();

Is that the right way?

Thanks

Upvotes: 0

Views: 605

Answers (1)

csano
csano

Reputation: 13686

Looks right to me. The only thing I'd do differently is refactor that code a little bit so that you're not duplicating the query.OrderBy() logic.

Upvotes: 1

Related Questions