This project has moved. For the latest updates, please go here.

Dynamic OrderBy

Feb 7, 2012 at 12:52 PM

Hi,

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.

eg
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

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

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

Regards,
Adrian

Coordinator
Feb 7, 2012 at 1:19 PM

hi Adrian,

check this link: http://camlex.codeplex.com/discussions/250635. Vladimir explained this behavior and showed solution of this problem. It is often problem with C# lambda expressions.

Feb 7, 2012 at 1: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.

Regards,
Adrian