LINQ Multiple order if not using lambda expressions

Possible duplicate:
Multiple "sort by" in LINQ

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

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

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 that works after the decending keyword (e.g. orderby count descending then searchquery).

Any ideas?

+4
source share
2 answers

Put a comma after descending and specify the next thing to sort (optionally adding descending ), etc.

+7
source

Just add the code to mlorbetske if you have the Customer class as follows:

 public class Customer { public string Name; public DateTime MemberSince; } 

Then you can do the ordering as follows:

 var q = from c in Customers orderby c.MemberSince.Date descending, c.Name select c; 
0
source

All Articles