Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6006915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:36:27+00:00 2026-05-23T01:36:27+00:00

I am using Linq to filter list of objects and to sort them, like

  • 0

I am using “Linq” to filter list of objects and to sort them, like

myList.Where(x => x.Item!= "SF" && x.AdSize == minadSize)
      .OrderBy(x => x.ManufacturingDate)
      .OrderBy(x=>x.ExpiryDate);

I doubt whether i am doing it right or not that is if i want to “sorting” on multiple fields then is it necessary to use multiple Order By clause cant it be done with single “OrderBy”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:36:28+00:00Added an answer on May 23, 2026 at 1:36 am

    Don’t use multiple OrderBy calls – use OrderBy followed by ThenBy:

    var query = myList.Where(x => x.Item!= "SF" && x.AdSize == minadSize)
                      .OrderBy(x => x.ManufacturingDate)
                      .ThenBy(x => x.ExpiryDate); // Could add more ThenBy calls
    

    If you use OrderBy twice, it will reorder the already-ordered-by-date list by expiry-date, whereas I assume you only want to order by expiry date for items with an equal manufacturing date, which is what the above does.

    Obviously there’s a ThenByDescending method too. For example:

    var query = people.OrderBy(x => x.LastName)
                      .ThenBy(x => x.FirstName)
                      .ThenByDescending(x => x.Age)
                      .ThenBy(x => x.SocialSecurity);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to filter a list of objects using linq. When i filter by
Using LINQ to Entities, how can I determine if any item from a List
Using LINQ to XML, XElements and XAttributes I'd like to filter a query using
Using LINQ to entities, I'm trying to filter a list based on another list.
I need to filter a linq query using a list of filters and I
Is there a pattern using Linq to dynamically create a filter? I have the
Using LINQ to Entities sounds like a great way to query against a database
using Linq-to-SQL I'd like to prefetch some data. 1) the common solution is to
I'm doing the following code to filter a list of objects before it gets
I have a list of Foos that I would like to filter according to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.