5

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?

0

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

Comments

0

Just to add some code to mlorbetske answer, if you have Customer class like this:

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

You could then perform an ordering like this:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.