System.Linq.Dynamic does not support OrderByDescending("someColumn")?
Solution 1
Assuming that you are using the DynamicQuery Helper files from the Microsoft sample library (Which are in the namespace System.Linq.Dynamic) then after reading the source code it looks like you need to specify the ordering you want as follows:
myDataSource.OrderBy("someColumnName descending")
Solution 2
If you're using string values (like me) you'll have to concatenate it to the string like this:
myDataSource.OrderBy(columnName + " descending");
Don't forget to add a space before 'descending' otherwise you'll get an error.
Marko
Updated on June 19, 2022Comments
-
Marko almost 2 years
Ok so in our project I'm using System.Linq.Dynamic library but I just noticed that I cannot do the following:
myDataSource.OrderByDescending("someColumnName")
Because I get the following error:
Overload resolution failed because no accessible
OrderByDescending
can be called with these arguments...It seems that the Library only support
OrderBy("someColumnName")
. Is there a reason for this and how would I bypass this issue if I want to reorder the records in descending order? Do I have to userReverse()
for exampleOrderBy("someColumnName").Reverse()
? Seems like a hack...Any advice would be greatly appreciated...
-
Sebastian Siek about 12 yearsI thought that OrderByDescending method does not accept only 1 string parameter ?!
-
Leom Burke about 12 yearsSorry - I mistyped the answer. The OrderBy method in the DynamicQuery helper from Microsoft allows you to specify comma-separated string orderings such as this.
-
Marko about 12 yearsYes this was the answer I was looking for. If I might add you can actually just say myDataSource.OrderBy("someColumnName DESC") in other words you don't have to type the entire descending word.
-
Pinte Dani about 5 yearsWorks, although not intuitive at all from the Framework design. It would have been more clear if System.Linq.Dynamic would contain also a method for OrderByDescending which accepts only a string parameter, like OrderBy