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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:28:47+00:00 2026-06-11T00:28:47+00:00

Basic Details I have a linq statement that grabs some records from a database

  • 0

Basic Details

I have a linq statement that grabs some records from a database and puts them in a System.Linq.Enumerable:

var someRecords = someRepoAttachedToDatabase.Where(p=>true);

Suppose this grabs tons (25k+) of records, and i need to perform update operations on all of them. to speed things up, I have to decided to use paging and perform the operations needed in blocks of 100 instead of all of the records at the same time.

The code in questions is used in two places: a service method that updates a lot of values in a database, and an integration test that gets the old and updated values to make sure the update was performed correctly.

The Question

The line in question is the line where I count the number of records in the subset to see if we are on the last page; if the number of records in subset is less than the size of paging – then that means there are no more records left. What I would like to know is what is the fastest way to do this?

Code in Question

int pageSize = 100;
bool moreData = true;
int currentPage = 1;
while (moreData)
{
   var subsetOfRecords = someRecords.Skip((currentPage - 1) * pageSize).Take(pageSize); //this is also a System.Linq.Enumerable
   if (subsetOfRecords.Count() < pageSize){ moreData = false;} //line in question
   //do stuff to records in subset
   currentPage++;
}

Things I Have Considered

  1. subsetOfRecords.Count() < pageSize
  2. subsetOfRecords.ElementAt(pageSize – 1) == null (causes out of bounds exception – can catch exception and set moreData to false there)
  3. Converting subsetOfRecords to an array (converting someRecords to an array will not work due to the way subsetOfRecords is declared – but I am open to changing it)

I’m sure there are plenty of other ideas that I have missed.

  • 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-11T00:28:49+00:00Added an answer on June 11, 2026 at 12:28 am

    use the parallels library. It will handle the paralellezation and paging for you automatically. Is the order that the records are processed in important?

    var someRecords = someRepoAttachedToDatabase.Where(p=>true); 
    Parallel.Foreach(someRecords, record=>DoSomethingWithRecord(record));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a basic signalr hub that accepts a call from a client,
I have a basic CRUD form that uses PageMethods to update the user details,
I've developed a basic CXF JAX-WS web service. Some details of web service, interface:
Basic question here - I have many lines of code that look something like:
I have a simple app I am messing around with its a basic Master/Details
I have a LINQ query that returns all absences for an employee. The first
i have the following code: HTML <div id=step-holder> <div class=step-no>1</div> <div class=step-dark-left><a href=#>Basic details</a></div>
Basic Information I have a rails app A that is connected to a mysql
I have a basic jQuery tabs system going: $(document).ready(function(){ $('#tabs div.jdiv').hide(); $('#tabs div.jdiv:first').fadeIn(slow); $('#tabs
I have a database with 'transactions' and 'transaction_lines'. A transaction has the basic shared

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.