如何确定NHibernate ICriteria对象的排序顺序?

时间:2009-08-05 13:00:32

标签: c# nhibernate icriteria

使用AddOrder方法检索添加到ICriteria对象的Orders列表的最佳方法是什么?我相信这必须使用Reflection完成,但需要反思的是什么?

这样做的目的是我想将排序顺序传递回UI,以便可以向用户提供排序顺序的指示。

1 个答案:

答案 0 :(得分:2)

var impl = session.CreateCriteria<User>().AddOrder(Order.Asc("Id")) as CriteriaImpl;

foreach (CriteriaImpl.OrderEntry entry in impl.IterateOrderings())
{
Order order = entry.Order;
    // now you have the order and you can either parse it : "propertyName asc" 
                                                         or "propertyName desc"
    // or you can check it out in debug, it has a few protected fields that you could reflect. 
    // not sure if there's another way.
}