Check if Linq IQueryable has an order applied

Is there a way to find out if an IQueryable OrderBy object is used in its expression tree?

The scenario that I have is that the grid control has paging and sorting per column. However, sorting is not applied by default, so in this case Linq to SQL makes a terribly huge choice for row counting, so in all scenarios I need to provide an order, but I should only use the default order with the primary key if no other order is specified.

So is this possible?

+7
c # linq expression-trees
source share
1 answer

You can find out by checking the query expression tree using the custom ExpressionVisitor or any recursive traversal mechanism of your choice.

I feel that your code is poorly designed. You should probably just keep the fact that the order was applied somewhere like bool . Perhaps the information flow of your application should be locked.

Using this verification method, you recover this information in a hacker way.

+6
source share

All Articles