代码之家  ›  专栏  ›  技术社区  ›  Chris Shouts

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

  •  1
  • Chris Shouts  · 技术社区  · 17 年前

    使用AddOrder方法检索添加到ICriteria对象的订单列表的最佳方法是什么?我相信这必须通过反思来实现,但反思什么呢?

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

    1 回复  |  直到 17 年前
        1
  •  2
  •   sirrocco    17 年前
    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.
    }
    
    推荐文章