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

The Archive Base Latest Questions

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

I recently experienced a performance problem in Entity Framework querying against SQL Server 2008.

  • 0

I recently experienced a performance problem in Entity Framework querying against SQL Server 2008. I managed to fix the issue, but I don’t understand why my fix worked. I’m using a collection of Guids with a .Contains() method to generate an IN clause in SQL. Here’s the original code (table names changed to protect the innocent):

Guid[] values = filter.Split(',').Select<String, Guid>(d => new Guid(d)).ToArray();


returnValue = returnValue.Where(t => values.Contains(t.WorkItem.Requirement.Project.ProjectId));

This query takes ~20 seconds for execution when there are > 150 ProjectID’s. By changing the location of the .Contains() I can speed things up dramatically. Here’s the refactor:

Guid[] values = filter.FilterValue.Split(',').Select<String, Guid>(d => new Guid(d)).ToArray();

var projects = from p in context.DC_DEF_Project
               where values.Contains(p.ProjectId)
               select p;

returnValue = from t in returnValue
              join p in projects on t.DC_DEF_ProjectWorkItem.DC_DEF_ProjectRequirement.ProjectId equals p.ProjectId
              select t;

This code takes ~0.125 seconds on the same data set as the above query.

I’m sure there’s a sane reason for this, but my curiosity is killing me. What is it?

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

    My guess would be that the first one results in sql with a bunch or ORs evaluated against the foreign key on workitems after all the joins where the second joins mach to projects by it’s primary key and evaluates the 150 ids only once then joins that to the other tables.

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

Sidebar

Related Questions

I recently became involved with a new software project which uses SQL Server 2000
I'm decently experienced with Python and Java, but I recently decided to learn C++.
I am experienced in C# but not in C++. Recently my Windows CE 5
I don't have much experience with Serial I/O, but have recently been tasked with
I have worked with Django before and have recently seen the Play framework .
Professionally I am a back-end Java developer, but recently I've been interested in writing
I'm a fairly experienced programmer and I've just recently discovered node.js. I love JavaScript
I am an experienced Visual Studio developer who has recently taken on an OSX
I'm a moderately experienced Java / C# programmer, and I've recently started learning C++.
I started using Hibernate only recently. While I was playing with it, I experienced

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.