This project has moved and is read-only. For the latest updates, please go here.

Dynamic OrderBy

Feb 7, 2012 at 1:52 PM


first of all, great project! With the upcoming (?) support for "In" and taxonomies this is could definitely become one of my standard tools.

I have an issue with dynamic Order By. I have read the blog post on the subject which appears to get what I want. The problem I've found is that each lamda order expression must use a different lamda.

Adding ordering expressions (later used in a .OrderBy-statement) like this:

string[] orderCols = new string[] { "First", "Second" };
foreach (string orderCol in orderCols)
 orderByExpressions.Add(x => x[orderCol] as Camlex.Desc);


will create the following CAML

<FieldRef Name="Second" />
<FieldRef Name="Second" />

Is this "by design" or is there something I can do differently? My challenge is that orderCols can be of varying length.


Feb 7, 2012 at 2:19 PM

hi Adrian,

check this link: Vladimir explained this behavior and showed solution of this problem. It is often problem with C# lambda expressions.

Feb 7, 2012 at 2:24 PM

I see! I had a feeling it was more related to the .Net-framework than the Camlex-implementation.

Thank you for your quick response.