views:

143

answers:

1

What is the best way to retrieve the list of Orders added to an ICriteria object using the AddOrder method? I believe this will have to be accomplished using Reflection, but what to reflect on?

The purpose of doing this is that I would like to pass the sort order back to the UI so an indication of the sort order can be provided to the user.

+1  A: 
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.
}
sirrocco
Cheers m8, exactly what I was looking for!
Chris Shouts
Glad I could help :)
sirrocco
Excellent, I needed this info as well, and I only found it on Stack Overflow, thanks sirrocco
CubanX