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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:36:37+00:00 2026-05-13T06:36:37+00:00

A lot of the LINQ to SQL that I’ve been doing involves reading data

  • 0

A lot of the LINQ to SQL that I’ve been doing involves reading data from a table and then calling the ToList() extension method and using the data in memory. However, I now want to use LINQ to SQL to process more records that can fit in memory. This is the pattern that I’ve come up with so far:

int skip = 0;
IList<Record> records = new List<Record>();
do
{
    records = DBRecords.Skip(skip).Take(1000).Select(a => new Record
    {
         // Set values here...
    }).ToList();
    foreach (Record r in records)
    {
        yield return r;
    }
    skip += 1000;
} while (records.Count > 0);

This allows me to pull 1000 records at a time and return them in batches to the app. However, I know that there must be a better way of doing 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-05-13T06:36:37+00:00Added an answer on May 13, 2026 at 6:36 am

    linq is lazy evaluated, however ToList() will realize the whole result. You can probably just drop the ToList() and return the result of your query directly. Processing the result in the caller in a foreach block will do so lazily.

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

Sidebar

Related Questions

I've been doing a lot of implementation in Linq recently, and it suddenly occurred
I've been checking my application with linq 2 sql profiler, and I noticed that
I have a LINQ to SQL class that I am reading into a List.
I have a table that contains a lot of data, where we particularly care
In one of our project we're using Linq-to-SQL to get data from our database.
This is linq-to-sql I have a lot of different classes all doing the same
I am calling a giant stored proc via linq to sql that brings back
So far I've been working with MVC3 with Linq to Sql so that all
We have a program that uses Linq-To-Sql and does a lot of similar queries
Although I have been through a number of posts that discuss Linq to SQL

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.