Check if a Linq IQueryable has an order by applied

c# expression-trees linq

Question

Is there a method to determine if an IQueryable object's expression tree has an OrderBy?

I have a grid control that allows for paging and column-by-column sorting. However, there is no default sort applied, therefore in this instance Linq to SQL does an exorbitantly large select for the number of rows. I must always supply an order by, but I should only do so if no other order has been supplied.

Is that so then?

1
7
7/17/2013 10:28:20 AM

Accepted Answer

Using a customized tool, you may examine the query's expression tree to learn more.ExpressionVisitor or any preferred method of recursive traversal.

Your code seems to be poorly constructed, in my opinion. You should definitely merely keep a record of the fact that an order has been placed someplace.bool . Perhaps your app's information architecture has to be changed.

You are shadily obtaining this information using this inspection technique.

6
7/17/2013 10:34:38 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow