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 7458771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:29:45+00:00 2026-05-29T13:29:45+00:00

I need to order the articles stored in a database by descending publication date

  • 0

I need to order the articles stored in a database by descending publication date and then take the first 20 records after the article with Id == 100.

This is what I would like to do with Linq:

IQueryable<Article> articles = 
    db.Articles
    .OrderByDescending(a => a.PublicationDate)
    .SkipWhile(a => a.Id != 100)
    .Take(20);

However, this generates a NotSupportedException because SkipWhile is not supported in Linq to Sql (see here).

A possible solution is to execute the query and then apply SkipWhile using Linq to Object:

IEnumerable<ArticleDescriptor> articles = 
    db.Articles
    .OrderByDescending(a => a.PublicationDate)
    .ToList()
    .SkipWhile(a => a.Article.Id != 100)
    .Take(20);

But this means I need to load the whole ordered list into memory first and then take 20 articles after the one with Id == 100.

Is there a way to avoid this huge memory consumption?

More in general, what is the best way to achieve this in SQL?

  • 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-29T13:29:46+00:00Added an answer on May 29, 2026 at 1:29 pm

    If, as I’m guessing from the column name, PublicationDate doesn’t change, you can do this in two separate queries:

    • Establish the PublicationDate of the Article with Id == 100
    • Retrieve the 20 articles from that date onwards

    Something like:

    var thresholdDate = db.Articles.Single(a => a.Id == 100).PublicationDate;
    var articles = 
        db.Articles
        .Where(a => a.PublicationDate <= thresholdDate)
        .OrderByDescending(a => a.PublicationDate)
        .Take(20);
    

    It might even be that LINQ to SQL can translate this:

    var articles = 
        db.Articles
        .Where(a => a.PublicationDate 
                 <= db.Articles.Single(aa => aa.Id == 100).PublicationDate)
        .OrderByDescending(a => a.PublicationDate)
        .Take(20);
    

    but that may be too complex for it. Try it and see.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three mysql tables, first holds information about articles (Article ID, author ID,
After reading 100's of articles on here about how to create a DropDown List
i'm checking this link: http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html It says that in order tu ouse C2DM, you
I need to order by 2 columns using the entity framework. How is that
I'm starting research on what I'd need in order to build a user-level plugin
I need to change the order of headers, I'm using this: HttpWebRequest request =
I need to used dynamic order query in mysql and i have successfully achieved
In order to create the proper queries I need to be able to run
i need to get number of order highlighted element (by javascript, jquery): <li>A</li> <li>B</li>
I need to learn C++ in order to learn building Nokia WRT and or

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.