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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:10:41+00:00 2026-05-21T09:10:41+00:00

Question related to how ORM (Linq to SQL,EF 4) handles loading of data. Is

  • 0

Question related to how ORM (Linq to SQL,EF 4) handles loading of data. Is the entire data set loaded, if so can we prevent the entire data set from loading and load a subset? For example when instantiating the context and querying it seems like there would be a huge performance issue if all data was returned (hundreds of thousand records) versus instantiating a connection, executing a proc for given subset of data and querying for this subset of data. I have not seen many threads address this, thanks in advance!

  • 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-21T09:10:43+00:00Added an answer on May 21, 2026 at 9:10 am

    No it doesn’t, as Linq to Sql/Eft will parse the query to produce an optimized sql query to retrive your data, with that being said a misuse of a extension method (which calls GetEnumrator()) or query might end up loading all items from a Table.

    Misuse of extension methods that call GetEnumerator()

    context.Books.ToList().Where(somePredicate).Select(someSelector);
    

    This will cause the whole Books table to be loaded, since the ToList() will invoke the sql query to retrive all Book objects. From there you Where and Select are actually operating over Linq to objects and not Linq To Sql/Entities.

    context.Books.Where(somePredicate).Select(someSelector).ToList();
    

    Simply pushing your .ToList() to the end of the statement will cause EF to parse the query into a valid sql query and retrieve a portion of your books when .ToList() is invoked.

    Misuse of Func<T, bool>

    Consider the following,

    Func<Book, bool> predicate = b=>b.Id == 3;
    context.Where(predicate).ToList();
    

    Now this looks perfectly valid, however once you run the query you will find the context is loading all Books, what gives? Simply put EF can not parse the Func<T, bool> predicate to valid sql syntax since a Func<> is just a delegate. This simple mistake can lead to EF loading all Books into the context and then running Linq to Objects against the loaded Books.

    Expression<Func<Book, bool>> predicate = b=>b.Id == 3;
    context.Where(predicate).ToList();
    

    Now here we are going to use an Expression<Func<Book, bool>> which is simply an expression tree, EF knows how to parse an expression tree and is able to create a valid sql statement that only loads one Book with and Id of 3.

    I am sure other people will be able to chime in with a few more examples that can cause the whole Table to be loaded, however these are the most likely you will run into.

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

Sidebar

Related Questions

Question related to PHP memory-handling from someone not yet very experienced in PHP: If
I took this sample code here : Django ORM: Selecting related set polls =
Another question related to this one . I have a List<SortableObjects> that is the
(First question related to iPhone development, so apologies for sounding off-track.) I'm creating a
Quick question related to IIR filter coefficients. Here is a very typical implementation of
I have a question related to this one . I don't want to do
As a follow up question related to my question regarding efficient way of storing
I have a modeling question related to profiles. Firstly, I have looked into using
I have a question related to this one : I'm trying to attach an
I have a question related to understanding of how python dictionaries work. I remember

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.