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 __as开发者_如何转开发cending, 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
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.
精彩评论