Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a List object. I am converting this to IQueryable by calling a method AsQueryable().

I need to do sorting on multiple columns say for ex. four columns say col1, col2 col3 & col4 using the expressing tree only. Any one has ideas, how to do that.

thanks

Any help appriciated...

What I have tried:

C#
List<employee> obj = new List<employee>
query = obj.AsQueryable<employee>()

var paramterExpression = Expression.Parameter(typeof(Employee));

Expression<func><employee> orderByExpression = 
 (Expression<func><employee>)Expression.Lambda(Expression.PropertyOrField(paramterExpression, "EmpName"), paramterExpression);

query.OrderBy(orderByExpression).


the above code is for one column, for the second column some people are saying to use <ode>thenby. beyond that nobody says how to do that.
Posted
Updated 24-Mar-18 0:49am
v4
Comments
Tomas Takac 6-May-16 2:22am    
I don't understand what is the problem. You clearly know how to build an expression. You also know you need to use ThenBy() for subsequent columns. What exactly is stopping you?

1 solution

C#
query.OrderBy(col1).ThenBy(col2).ThenBy(col3).ThenBy(col4);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900