开发者

Reusable OrderBy with QueryOver in NHibernate problem

开发者 https://www.devze.com 2023-03-02 11:49 出处:网络
I have that code using ICritiria public virtual IEnumerable<T> GetPagined(int __pageIndex, int __pageSize, string __order, bool __as开发者_如何转开发cending, out int __total)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号