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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:17:32+00:00 2026-05-15T23:17:32+00:00

I have a L2S query with several joins that should returns 11 records in

  • 0

I have a L2S query with several joins that should returns 11 records in about 3 seconds. However, it times out after 30 seconds unless I specify a Take parameter (i used Take(20) even though it only returns 11 records) in which case it returns in the expected time frame of 3 seconds with the 11 records.

The query looks like this:

(from q in TransmittalDetails where q.TransmittalHeader.TransmittalEntityID == 196
      && q.TransmittalHeader.DateRangeBeginTimeID == 20100101
      && q.TransmittalHeader.ScenarioID == 2
      && q.LineItem.AccountType.AccountCategory.AccountGroup.
             AccountSummary.AccountSummaryID == 6
 select new {
q.LineItem.AccountType.AccountCategory.AccountGroup.AccountGroupID,
q.LineItem.AccountType.AccountCategory.AccountGroup.AccountGroup1
   }).Distinct()

This generates some SQL that looks like this:

DECLARE @p0 Int = 196
DECLARE @p1 Int = 20100101
DECLARE @p2 Int = 2
DECLARE @p3 Int = 6

SELECT DISTINCT [t5].[AccountGroupID], [t5].[AccountGroup] AS [AccountGroup1]
FROM [dbo].[TransmittalDetail] AS [t0]
INNER JOIN [dbo].[TransmittalHeader] AS [t1] ON [t1].[TransmittalHeaderID] = 
   [t0].[TransmittalHeaderID]
INNER JOIN [dbo].[LineItem] AS [t2] ON [t2].[LineItemID] = [t0].[LineItemID]
LEFT OUTER JOIN [dbo].[AccountType] AS [t3] ON [t3].[AccountTypeID] = 
   [t2].[AccountTypeID]
LEFT OUTER JOIN [dbo].[AccountCategory] AS [t4] ON [t4].[AccountCategoryID] = 
   [t3].[AccountCategoryID]
LEFT OUTER JOIN [dbo].[AccountGroup] AS [t5] ON [t5].[AccountGroupID] = 
   [t4].[AccountGroupID]
LEFT OUTER JOIN [dbo].[AccountSummary] AS [t6] ON [t6].[AccountSummaryID] = 
   [t5].[AccountSummaryID]
WHERE ([t1].[TransmittalEntityID] = @p0) AND ([t1].[DateRangeBeginTimeID] = @p1) 
   AND ([t1].[ScenarioID] = @p2) AND ([t6].[AccountSummaryID] = @p3)

Now, the truly bizarre part is that if I execute that SQL in Management Studio, it returns 11 rows in 3 seconds, yet the linq query that generates it will timeout after 30 seconds of activity.

Specifying the Take parameter just doesn’t make much sense. Am I hitting some bug?

Note: The code times out without the Take() parameter whether i execute it from my app, or Linqpad. Likewise, in both app and linqpad it works fine with a Take() parameter. Also, without the distinct it only returns 19 rows.

  • 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-15T23:17:33+00:00Added an answer on May 15, 2026 at 11:17 pm

    Compare the execution plan for the query with and without the .Take (top n). You probably got a bad execution plan for the query the first time, and adding Take just changed the query so it was compiled again.

    Drop the execution plan with sp_recompile or dbcc freeproccache and see if that makes a difference.

    You can also use a profiler to extract more information about query cost, execution plans etc…

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

Sidebar

Related Questions

I have a L2S query that looks like this: using (MyDC TheDC = new
Have a query that should hopefully be nice and simple to answer. I have
I have a fairly complex query (that includes a table valued function to allow
I have a small L2S database that was generated with the L2S CreateDatabase command.
I have a query that looks like this: using (MyDC TheDC = new MyDC())
I have a question regarding a problem with L2S, Autogenerated DataContext and the use
Have deployed numerous report parts which reference the same view however one of them
I have the following query: from p in dataContext.Repository<IPerson>() join spp1 in dataContext.Repository<ISportsPerPerson>() on
I have a table that I use for caching json strings and once in
Such a task: we have 2 tables in our L2S Entity classes. It needs

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.