locked
Find out if DbQuery<T> is already sorted RRS feed

  • Question

  • Hello,

    Is there a chance to find out if a DbQuery<T> is already sorted? I mean if the actual query already has a "order by" condition indluced (without using the ToString() method on the dbquery :) )

    Thanks in advance,

    Wolfgang

    Wednesday, July 18, 2012 3:04 PM

Answers

  • Hi Wolfgang,

    Thank you for your post.

    Only ToString() method can display the actual query, so I am afraid that you cannot know if query is sorted unless use ToString() method.

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Alexander Sun Friday, August 3, 2012 2:20 AM
    Thursday, July 19, 2012 9:33 AM

All replies

  • Hi Wolfgang,

    Thank you for your post.

    Only ToString() method can display the actual query, so I am afraid that you cannot know if query is sorted unless use ToString() method.

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Alexander Sun Friday, August 3, 2012 2:20 AM
    Thursday, July 19, 2012 9:33 AM
  • Since DbQuery<T> implements IQueryable<T> you might check the query expression from IQueryable.Expression (you need a cast since it's explicit implementation). You might want to use an ExpressionVisitor-derived class to walk the expression tree and look for a MethodCallExpression to Queryable.OrderBy.
    Thursday, July 19, 2012 10:21 AM