Is there any way to find out if an IQueryable object has an OrderBy applied within its expression tree?
The scenario I have is that a grid control has paging enabled, and sorting per column. However there is not a sort applied by default, so in this case Linq to SQL does a horribly huge select for the row count, so in all scenarios I need to provide an order by, however I should only apply a default order by primary key if no other order has been specified.
So is this possible?
SELECT ROW_NUMBER() OVER (ORDER BY <every-single-column-)
if there is no explicit orderby criteria applied to the underlying query. So for example I have a query which takes 30 seconds to run on the DB without an order by, but takes less than 1 second with an orderby applied. So if I can explicitly set the primary key as the orderby if there is no automatic orderby set from the sort expression of the grid, then I can shave off a ton of time wasted because of the badly composed Linq query. – Grofit Jul 17 '13 at 11:06typeof(IOrderedQueryable<T>).IsAssignableFrom(myQueryable.Expression.Type)
as suggested in stackoverflow.com/questions/5071426/… ? – Dejan Jun 30 '15 at 12:48