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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:34:45+00:00 2026-06-07T22:34:45+00:00

class User { public int Id {set;get;} public int ExternalId {set;get;} } I have

  • 0
class User {
    public int Id {set;get;}
    public int ExternalId {set;get;}
}

I have this class defined. I am using code first EF.

public class FooContext : DbContext {
    public DbSet<User> Users { set; get; }
}

So when I do the following:

db.Users.ToList().where(x=>x.ExternalId == externalId);

I am curious if this does the following:

select whatever from Users where ExternalId = 'id I passed in';

or it loads all the users to the memory and do the Linq in memory?

What’s the best practice to query a table with a condition (where clause)?

  • 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-07T22:34:46+00:00Added an answer on June 7, 2026 at 10:34 pm

    The ToList() call is going to cause EF to pull all of the user records back from the DB. Your call to the Where extension method will be run against the set in memory. If you change the order of your calls, it will only select the needed records from the db, like this:

    db.Users.Where(x=>x.ExternalId == externalId).ToList();
    

    This is because Entity Framework uses delayed execution. The call to the database doesn’t happen until the actual records are enumerated in your calling code. Until you use the results, the query is just an expression tree waiting to be executed. If you look at the Where() method it’s return type is IQueryable. When you call ToList() you are essentially converting from an expression tree (IQueryable) to a generic list of users. This requires EF to run the db query to return the results.

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

Sidebar

Related Questions

Hello I have like this 2 tables class User public int UserId{get;set;} { ....
my code like below public class User { public int ID { get; set;
I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have this Class: public class User { public string id{ get; set; }
I have the following entity: public class User { public int ID {get; set;}
I have a class: public class User { public virtual int Id { get;
So, i have this object for exemple: public class User { public int Id
public class User { public int Id {get;set;} public string Name {get;set} public ICollection<User>
Given the following classes: public class User { public int Id {get;set;} public PersonName
i have a Class like public class user { public int ID { get;

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.