Dilan Quesada
Dilan Quesada

Reputation: 37

Trying to orderby with case when clause for MultiDocumentQuery?

I am trying to get all my pagetypes from kentico, but I would like to order them by all the page types that starts with the letter "F", first and then the other pages alphabetically.

What I am trying is:

1) MultiDocumentQuery docQuery = DocumentHelper.GetDocuments().Type("forms").OnSite(SiteContext.CurrentSiteID).Published(); 2) docQuery.OrderBy("FormName");

But what I need is to order em using something like this (SQL):

SELECT FormName FROM Forms order by case when FormName like 'C%' then 0 else 1 end, FormName

What I cant do is to translate the case when properly to c#, and implement it to docQuery. So the result should be for example,:

  1. Form1
  2. Form2
  3. Form3
  4. A...
  5. B...

Upvotes: 0

Views: 176

Answers (1)

mnield
mnield

Reputation: 1869

I think I'd look at adding your case statement in the columns rather then the where like this:

CASE WHEN FormName LIKE 'F%' THEN 0 ELSE 1 END AS IsForm

This way you can have a new column called IsForm and can have an Order by of:

IsForm, FormName

Upvotes: 1

Related Questions