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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:50:53+00:00 2026-05-27T20:50:53+00:00

So I write a Linq query and it takes 16 seconds to run. Decide

  • 0

So I write a Linq query and it takes 16 seconds to run. Decide to see what the query plan is, so I get that out of Linq to SQL Profiler and the query only takes 2 seconds to run. sigh

After spending most of the day poking at things and finally getting around to using SQL Server Profiler I see that Linq2SQL is using sp_executesql to run the query. I understand that it’s supposed to improve performance because it’s more likely to re-use the execution plan… but it seems to have chosen a horrible execution plan to use.

The weirder part is that it only gets slow if I join a specific table, and I have no idea why that specific table is causing a problem.

EDIT Just to clarify the actual issue here:

It’s actually getting to different queries. One is, essentially,

SELECT col1, col2, ... FROM table1, table2 WHERE table1.val IN (1234, 2343, 2435)

The other is

EXEC sp_executesql 'SELECT col1, col2, ... FROM table1, table2 WHERE table1.val IN (@p1, @p2, @p3)', 
N'@p0 int,@p1 int,@p2 int,@p3 int',
@p0=1234, @p1=2343, @p3=2435
  • 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-27T20:50:54+00:00Added an answer on May 27, 2026 at 8:50 pm

    Your problem doesn’t stem from the use of sp_executesql, and so circumventing it (which you can’t) will not solve your problems. I suggest you read Erland Sommarskog’s excellent article:

    Slow in the Application, Fast in SSMS?
    Understanding Performance Mysteries

    This will give you a deep understanding of why you’re getting a performance difference, how to diagnose and consistently reproduce it, and finally, how to solve it.

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

Sidebar

Related Questions

I am trying to write a linq query that will only return certain columns
How can I write a LINQ query that returns an hierachical anonymous type from
What's the best way to write a LINQ query that inserts a record and
How can I write a query similar to this one in LINQ to SQL
I'm trying to write the following query in LINQ, but can't seem to get
How would one write a LINQ query which takes a hierarchical source data and
I'm trying to write some LINQ To SQL code that would generate SQL like
I'm trying to write a linq to sql method that handles sorting, paging, and
How to write a LINQ query that would return row of type Value with
How could I write an ORM that would convert LINQ into SQL? I already

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.