0

I would like to query with Linq as follows:

Public Sub sortquery(ByVal sortExp As String, ByVal sortDir As String)

Dim datestart As DateTime = Convert.ToDateTime("01/01/2014")

_availableActions = (From x In _Context.Actions Where x.dateDay >= datestart Order By sortExp).ToList()

The problem lies with Order By sortExp. sortExp is passed in as string. The string is in fact an actual column name, but is just called into the sub. I am just unsure how to get this sorted using the string (or how to convert the string to the respective column name).

drclayton
  • 63
  • 2
  • 10
  • possible duplicate of [Dynamic LINQ OrderBy on IEnumerable](http://stackoverflow.com/questions/41244/dynamic-linq-orderby-on-ienumerablet) – Gert Arnold Jun 16 '14 at 18:44

1 Answers1

0

I think this previous question might solve your problem.

https://stackoverflow.com/a/233505/1720848

If you use Marc's ApplyOrder implementation, then you'll be able to do something like:

 _availableActions = (From x In _Context.Actions Where x.dateDay >= datestart).OrderBy(sortExp).ToList()
Community
  • 1
  • 1
minerva
  • 436
  • 6
  • 16