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

  • Home
  • SEARCH
  • 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 9245355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:14:57+00:00 2026-06-18T09:14:57+00:00

What I want to do, is basically what this question offers: SQL Server –

  • 0

What I want to do, is basically what this question offers: SQL Server – How to display most recent records based on dates in two tables .. Only difference is: I am using Linq to sql.

I have to tables:

  • Assignments
  • ForumPosts

These are not very similar, but they both have a “LastUpdated” field. I want to get the most recent joined records. However, I also need a take/skip functionality for paging (and no, I don’t have SQL 2012).

I don’t want to create a new list (with ToList and AddRange) with ALL my records, so I know the whole set of records, and then order.. That seems extremely unefficient.

My attempt:

Please don’t laugh at my inefficient code.. Well ok, a little (both because it’s inefficient and… it doesn’t do what I want when skip is more than 0).

    public List<TempContentPlaceholder> LatestReplies(int take, int skip)
    {
        using (GKDBDataContext db = new GKDBDataContext())
        {
            var forumPosts = db.dbForumPosts.OrderBy(c => c.LastUpdated).Skip(skip).Take(take).ToList();
            var assignMents = db.dbUploadedAssignments.OrderBy(c => c.LastUpdated).Skip(skip).Take(take).ToList();

            List<TempContentPlaceholder> fps =
                forumPosts.Select(
                    c =>
                    new TempContentPlaceholder()
                    {
                        Id = c.PostId,
                        LastUpdated = c.LastUpdated,
                        Type = ContentShowingType.ForumPost
                    }).ToList();

            List<TempContentPlaceholder> asm =
                                assignMents.Select(
                                    c =>
                                    new TempContentPlaceholder()
                                    {
                                        Id = c.UploadAssignmentId,
                                        LastUpdated = c.LastUpdated,
                                        Type = ContentShowingType.ForumPost
                                    }).ToList();

            fps.AddRange(asm);

            return fps.OrderBy(c=>c.LastUpdated).ToList();

        }
    }

Any awesome Linq to SQl people, who can throw me a hint? I am sure someone can join their way out of this!

  • 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-06-18T09:14:58+00:00Added an answer on June 18, 2026 at 9:14 am

    First, you should be using OrderByDescending, since later dates have greater values than earlier dates, in order to get the most recent updates. Second, I think what you are doing will work, for the first page, but you need to only take the top take values from the joined list as well. That is if you want the last 20 entries from both tables combined, take the last 20 entries from each, merge them, then take the last 20 entries from the merged list. The problem comes in when you attempt to use paging because what you will need to do is know how many elements from each list went into making up the previous pages. I think, your best bet is probably to merge them first, then use skip/take. I know you don’t want to hear that, but other solutions are probably more complex. Alternatively, you could take the top skip+take values from each table, then merge, skip the skip values and apply take.

    using (GKDBDataContext db = new GKDBDataContext())
    {
         var fps = db.dbForumPosts.Select(c => new TempContentPlaceholder()
                    {
                        Id = c.PostId,
                        LastUpdated = c.LastUpdated,
                        Type = ContentShowingType.ForumPost
                    })
                    .Concat( db.dbUploadedAssignments.Select(c => new TempContentPlaceholder()
                    {
                        Id = c.PostId,
                        LastUpdated = c.LastUpdated,
                        Type = ContentShowingType.ForumPost
                    }))
                    .OrderByDescending( c => c.LastUpdated )
                    .Skip(skip)
                    .Take(take)
                    .ToList();
    
        return fps;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not really sure how to ask this question, but basically I want to
this question is very similar to another post I basically want to use the
Couldn't think of better phrasing for this question, but basically I want to store
This is a follow up to: this question Basically, I have a server loop
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
Basically i want to do this. aa causes a bad cast exception. NOTE: o
Basically i got this for loop and i want the number inputed (eg. 123)
I'm using this plugin and here is the code: http://jsfiddle.net/gm8t5/ Basically I want to
This is what I'm talking about: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ComboBox/ComboBox.aspx basically I want to have a drop
I've Googled for this but must be using the wrong keywords. Basically I want

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.