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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:54:39+00:00 2026-06-18T08:54:39+00:00

Basically I use Entity Framework to query a huge database. I want to return

  • 0

Basically I use Entity Framework to query a huge database. I want to return a string list then log it to a text file.

List<string> logFilePathFileName = new List<string>();
var query = from c in DBContext.MyTable where condition = something select c;
foreach (var result in query)
{
    filePath = result.FilePath;
    fileName = result.FileName;
    string temp = filePath + "." + fileName;
    logFilePathFileName.Add(temp);
    if(logFilePathFileName.Count %1000 ==0)
        Console.WriteLine(temp+"."+logFilePathFileName.Count);
}

However I got an exception when logFilePathFileName.Count=397000.
The exception is:

Exception of type ‘System.OutOfMemoryException’ was thrown.

A first chance exception of type ‘System.OutOfMemoryException’
occurred in System.Data.Entity.dll

UPDATE:

What I want to use a different query say: select top 1000 then add to the list, but I don’t know after 1000 then what?

  • 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-18T08:54:40+00:00Added an answer on June 18, 2026 at 8:54 am

    Most probabbly it’s not about a RAM as is, so increasing your RAM or even compiling and running your code in 64 bit machine will not have a positive effect, in this case.

    I think it’s related to a fact that .NET collections are limited to maximum 2GB RAM space (no difference either 32 or 64 bit).

    To resolve this, split your list to much smaller chunks and most probabbly your problem will gone.

    Just one possible solution:

    foreach (var result in query)
    {
        ....
        if(logFilePathFileName.Count %1000 ==0) {
            Console.WriteLine(temp+"."+logFilePathFileName.Count);
            //WRITE SOMEWHERE YOU NEED 
            logFilePathFileName = new List<string>(); //RESET LIST !|
        }
    }
    

    EDIT

    If you want fragment a query, you can use Skip(...) and Take(...)

    Just an explanatory example:

    var fisrt1000 = query.Skip(0).Take(1000);
    var second1000 = query.Skip(1000).Take(1000);
    

    …
    and so on..

    Naturally put it in your iteration and parametrize it based on bounds of data you know or need.

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

Sidebar

Related Questions

what I want to do is to use something like name=validate[required] basically use it
So, I just basically want to use AVFoundation Kit for playing my sound. I
basically what i want is redirect al request to use HTTPS instead of http
Basically, what I want is to use an alternative to the login cookies as
I am trying to create a completely dynamic way to query entity framework using
When using the Entity Framework there are basically two ways to create your model.
Basically I want to use a dynamic data website to maintain data in an
I'm writing a simple first app using Winforms, C#, VS2010, and Entity Framework. Basically,
i'm planning to use a combination of entity framework + plain sql access for
Basically put, I have an action that saves a form to a database, then

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.