Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Linq.Dynamic does not support OrderByDescending("someColumn")?

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 user Reverse() for example OrderBy("someColumnName").Reverse()? Seems like a hack...

Any advice would be greatly appreciated...

like image 255
Marko Avatar asked Mar 13 '12 15:03

Marko


2 Answers

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")
like image 82
Leom Burke Avatar answered Nov 20 '22 03:11

Leom Burke


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.

like image 28
xatz Avatar answered Nov 20 '22 03:11

xatz