使用AddOrder方法检索添加到ICriteria对象的Orders列表的最佳方法是什么?我相信这必须使用Reflection完成,但需要反思的是什么?
这样做的目的是我想将排序顺序传递回UI,以便可以向用户提供排序顺序的指示。
答案 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.
}