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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:54:07+00:00 2026-06-10T03:54:07+00:00

in my application i´m using SQL CE 4.0 and Entity Framework Code First. public

  • 0

in my application i´m using SQL CE 4.0 and Entity Framework Code First.

public class Customer : IEntityPoco
{
    public  int Id { get; set; }

    public  string Sex          { get; set; }
    public  string Titel        { get; set; }
    public  string FirstName    { get; set; }
    public  string SecondName   { get; set; }
    public  string LastName     { get; set; }
    public  string Fax          { get; set; }
    public  string Notice       { get; set; }
    public  DateTime LastChange { get; set; }

    public  int AddressId   { get; set; }
    public  Address Address { get; set; }

    public  ICollection<Sale> Sales { get; set; }
    public  ICollection<Customer> Partner1 { get; set; }
    public  ICollection<Customer> Partner2 { get; set; }
    public  ICollection<Phone> PhoneNumbers { get; set; }
    public  ICollection<Email> EmailAddresses { get; set; }
    public  ICollection<Corrospondence> Corrospondence { get; set; }
    public  ICollection<ShippingAddress> ShippingAddresses { get; set; }
}

thats what my model looks like,

var query = context.TeacherCustomers
    .Include(i => i.EmailAddresses)
    .Include(i => i.Corrospondence)
    .Include(i => i.Address.City.Country)
    .Include(i => i.ShippingAddresses)
    .Include(i => i.Sales.Select(f => f.BuildVersion.Product))
    .Include(i => i.PhoneNumbers)
    .Include(i => i.Partner1.Select(f => f.Address.City.Country))
    .Include(i => i.Partner2.Select(f => f.Address.City.Country))
    .AsNoTracking();

and that´s what my query look´s like. In my Business Logic i need all Email Addresses, Phone Numbers, … If i comment all Include Statements this query is executed in about 82ms, if all include statements are not commented the query takes about 52000ms (and it is not the first query so the database model is already compiled).

This post here explains the problem very good: How many Include I can use on ObjectSet in EntityFramework to retain performance?, but the solution given there is also not an option for me because my Database contains more then 10 000 entries and when i execute the query and then stepping through all customers returned by the query and calling context.Entry(customer).Reference(i => i.EmailAddresses).Load() takes also a lot of time.

So how can i create a query that has the same result as the query above but is executed faster?

help would be appreciated

  • 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-10T03:54:08+00:00Added an answer on June 10, 2026 at 3:54 am

    I am not sure if you will be able to get much performance out of this model. You are essentially cross joining all the tables, which will give you a huge table and a lot of records.

    I suggest to rethink your model, may be denormalize a bit, do you really need tables for emails, and phone numbers cant they be just multiple columns in the table (most apps do not need more than 2 mails or phone numbers).

    If there is nothing you can do about the model, I suggest load all tables separately like use one query to load all Customers, and one to load all emails and so forth then join them in the model. based on the statistics you have provided it will take you less than 400 ms to load all the data.

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

Sidebar

Related Questions

I'm building a .NET 4 WPF application using Entity Framework code first and SQL
Background We have a WinForms application with Entity Framework 4.2 code-first / FluentAPI using
I am using SQL Azure as database with code first technique of Entity framework
I have an ASP.NET MVC 3 application using an Entity Framework (4.3.1) Code First
I have a console application that is using code first Entity Framework 4.3.1. I
I'm developing a web application using ASP.NET MVC 3 and Entity Framework Code First
I'm using Entity Framework (4.3) and code first (along with SQL server 2012 localdb).
I developed the Windows Application using Entity Framework 4.0 with SQL Server. In development
I am using Entity Framework 4 in a desktop application with SQL Compact. I
I am using the Entity Framework in a web application that utilizes SQL server

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.