2011-05-02 49 views
0

我使用ICritiria可重複使用的排序依據與QueryOver NHibernate的問題

代碼
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>(); 
... 
} 

我正嘗試將其轉換成QueryOver ...問題是排序依據...我這樣做:

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

這是正確的方法嗎?

謝謝

+0

什麼是您的參數命名約定? :S – Phill 2011-05-03 01:21:44

回答

1

看起來很對我。我唯一不同的做法是重構代碼,以免重複query.OrderBy()邏輯。