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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:55:05+00:00 2026-06-15T06:55:05+00:00

I have entities in the context (memory), because I loaded them with Include()s. I

  • 0

I have entities in the context (memory), because I loaded them with Include()s.

I have about 25 entities (tph), and I’m running the following query on each of them:

actTph.TrainingProgramHistory_ConditionAndLoadParameter.Where(x => x.Level == 10).Select(x => x.ConditionAndLoadParameter).ToArray();

TrainingProgramHistory_ConditionAndLoadParameter, and TrainingProgramHistory_ConditionAndLoadParameter.ConditionAndLoadParameters are in memory, because when these queries are executed, SQL-profile logs nothing.

Each TPH has about 20 TrainingProgramHistory_ConditionAndLoadParameter related entities.

Running this query 25 times (on my 25 TPH entities) takes about 3 seconds!

If I refactor to this:

List<ConditionAndLoadParameter> measuredCalps = new List<ConditionAndLoadParameter>();
                    foreach (TrainingProgramHistory_ConditionAndLoadParameter tphCalp in actTph.TrainingProgramHistory_ConditionAndLoadParameter)
                    {
                        if (tphCalp.Level == 10)
                        {
                            measuredCalps.Add(tphCalp.ConditionAndLoadParameter);
                        }
                    }

Then it runs in 100msec or so.

How is Linq to Entities this slow for in-memory objects? What am I doing wrong?

  • 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-15T06:55:06+00:00Added an answer on June 15, 2026 at 6:55 am

    OK, was my bad 🙁

    The first snippet was in a method, which contained a log/trace-line which apparently used lock()-s inside it, and even though this method was called from the same thread, calling these locks slowed down the performance.

    In this case the foreach and linq query produced about the same performance after removing the locks.

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

Sidebar

Related Questions

So let's assume I have the following entities and their context configuration set up
I have 2 entities in CoreData (which are relevant to this). Let's call them
I have three entities: Country, State and City with the following relationships: When creating
The context is the following we have an MVC web application with a lot
I have attached entities to a context with EntityState.Unchanged which will be referenced by
I have been trying to find newly added entities on a context by using
I have an application that creates entities in offline mode then saves them to
OK, let's say that I have two entities, A and B. For each user,
I have three entities in my data context which inherit IFileData , but I
I have a problem with EF 4.1 Here are my entities and context: public

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.