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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:39:41+00:00 2026-05-23T11:39:41+00:00

Another question regarding EF: I was wondering what’s going behind the scenes when iterating

  • 0

Another question regarding EF:

I was wondering what’s going behind the scenes when iterating over a query result.

For example, check out the following code:

var activeSources = from e in entitiesContext.Sources
                    where e.IsActive
                    select e;

and then:

foreach (Source currSource in allSources)
{
   code based on the current source...
}

Important note: Each iteration takes a while to complete (from 1 to 25 seconds).

Now, I assume EF is based on DataReaders for maximum efficiency, so based on that assumption, I figure that in the above case, the Database connection will be kept open until I finish iterating over the results, which will be a very long time (when talking in terms of code), which is something I obviously don’t want.

Is there a way to fetch the entire data like I would’ve done with plain old ADO.NET DataAdapters, DataSets and the fill() method instead of using DataReaders?

Or maybe i’m way off with my assumptions?

In any case I would’ve loved to be pointed to a good source explaining this if available.

Thanks,

Mikey

  • 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-23T11:39:41+00:00Added an answer on May 23, 2026 at 11:39 am

    If you want to get all of the data up front, similar to Fill(), you need to force the query to execute.

    var activeSources = from e in entitiesContext.Sources
                        where e.IsActive
                        select e;
    
    var results = activeSources.ToList();
    

    After ToList() is called you will have the data and be disconnected from the database.

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

Sidebar

Related Questions

I've got another question regarding to basic Android programming: How can I access the
im reading Practical common Lisp as a result of another question . I just
Hey, I have a question regarding code structure, and was wondering what the best
Anybody? There is another question regarding this but the only answers were to code
This is a follow on from another question, my question is regarding the use
I read another post that answered a question regarding iterators for vectors of pointers.
I saw in another question regarding swing Timer API and your methods, preference stop();
I'm back with another question regarding Android databases. I'm storing a simple string into
I got another question regarding jQuery's architecture. $('div') constructs a new jQuery object: $('div')
I have an other active question HERE regarding some hopeless memory issues that possibly

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.