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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:16:01+00:00 2026-06-12T20:16:01+00:00

I have following simple query in ASP.NET MVC action method. IEnumerable<Company> query = unitOfWork.CompanyRepository.dbSet

  • 0

I have following simple query in ASP.NET MVC action method.

IEnumerable<Company> query = unitOfWork.CompanyRepository.dbSet
    .Include("Adresses.PhoneNumbers")
    .Include("Adresses.FaxNumber")
    .Include("Emails").Where(q => q.CustomerCompany == true);

This action method is called via ajax get request and sometimes it takes up to 25 secs! for just 40 Companies in database.Each of them has single Address and at most couple of PhoneNumbers and FaxNumbers.(Interestingly it sometimes takes 200-500 msecs, but very rare)

If I change this query to following

IEnumerable<Company> query = unitOfWork.CompanyRepository.dbSet
    .Where(q => q.CustomerCompany == true);

It only takes around 200 msecs.

So I am wondering why .Include is so expensive. My application is in production and I am using SQL Azure with Azure Web Sites.

Thanks.

  • 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-12T20:16:02+00:00Added an answer on June 12, 2026 at 8:16 pm

    The SQL generated is more complicated, but usually the performance is due to LINQ query compilation overhead. You need to profile to be sure. One possible fix is to use a precompiled query, which will be faster the second and subsequent times. A better fix is probably to use a projection of only the data you need, instead of including 4 entities in the query, which amounts to a SELECT * on all 4 tables. Another possible fix, if you need all of those full entities, is explicitly loading the details, which means more (but faster!) queries.

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

Sidebar

Related Questions

I have following tables (CustomerType, Customer and Company) in a data base: In asp.net,
I have implemented a simple jqGrid in my ASP.NET MVC 3 application. It shows
I have following rather simple query select count(*) from tbl t1, tbl t2 For
Lets suppose that I have the following simple query var q = from p
I have the following simple Java code: package testj; import java.util.*; public class Query<T>
I'm using MVC 4, EF 4.3 and the MVCScaffolding package. I have following simple
I have an ASP.NET MVC website. In my backend I have a table called
Let's say I have the following simple query SELECT TOP 1 name FROM months
I have the following simple Linq query: (from container in Container join containerType in
im using ASP.NEt to make a simple database query and return JSON formated data.

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.