Search code examples
.netlinqdynamic-datadynamic-linq

dynamic linq query


I have query to perform where the user will enter at runtime one of the columns to be included in the result set. And, I won't know until runtime how many columns he could choose from (he uploads a file that can contain a varying number of columns). I'd like to write the query where the index of the column is dynamic. What's the best way to do this kind of query?

Thanks.


Solution

  • You're looking for Dynamic LINQ.

    Alternatively, you could generate expression trees from the column names and call ThenBy in a loop.