Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ Multiple order by when not using lambda expressions [duplicate]

Tags:

c#

linq

Possible Duplicate:
Multiple “order by” in LINQ

I want to order some dataset by some field AND THEN some other field.

Using lambda expressions this would be easy (OrderBy.ThenBy), but how to do it when I have a syntax like this:

 int maxQueries = int.MaxValue;
        // finds the most search for queries
        var ordered = from p in searchLogs
        where !string.IsNullOrEmpty(p.SearchQuery)
        group p by new 
        { 
           SearchQuery = p.SearchQuery
        } 
        into pgroup
        let count = pgroup.Count()
        orderby count descending
        select new 
        { 
            Count = count, 
            SearchQuery = pgroup.Key.SearchQuery
        };

I can't seem to find a way which works after the decending keyword (like orderby count descending then searchquery)..

Any ideas?

like image 994
Lars Holdgaard Avatar asked Dec 22 '12 12:12

Lars Holdgaard


1 Answers

Put a comma after descending and specify the next thing to sort by (optionally adding descending) and so on

like image 77
mlorbetske Avatar answered Oct 13 '22 22:10

mlorbetske