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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:13:12+00:00 2026-06-02T16:13:12+00:00

We have a project using Entity Framework 4.1 Code First for data storage. It

  • 0

We have a project using Entity Framework 4.1 Code First for data storage. It was coded in such a way that EF is abstracted behind a repository pattern. When entities are fetched from a repository, the dataset is passed a huge list of include strings telling it all the related entities that should also be fetched. This results in an insanely huge query which can take 10 seconds to run – even when there is no data in the database!

There is already a lot of code written using the repository to access the database, I need to improve the performance ideally without breaking the pattern.

I am trying to change things so that when searching the database, no include strings are passed to the dataset (or just minimal include strings). When entities are fetched from the database, their related entities will be loaded through lazy loading when they are first accessed.

I have a class called Donation with a navigational property like this:

public virtual Employee Donor { get; private set; }

Both Donation and Employee classes have a private parameterless constructor. When using the include string “Donor”, I can fetch a list of Donations and they are returned with Donor attached.

When I fetch a Donation from the repository without the include string, Donor is usually returned as null. If co-incidentally I am logged in as the Employee in question, another query elsewhere in the system will have already fetched my Employee entity from the Employee repository. When this happens, Donation is returned with Employee set correctly! So clearly the data is being “lazy loaded” if it is already available from an earlier query. But in general I won’t have already queried for the Donor and all the other entities.

Can anyone suggest what I could be doing wrong? Sorry for the long question. I can post more bits of code if needed, but it is quite disparate. Thanks in advance!

  • 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-02T16:13:13+00:00Added an answer on June 2, 2026 at 4:13 pm

    I believe if you follow the guidelines on this page, http://msdn.microsoft.com/en-us/library/dd468057.aspx you should get the result you are after. Speficially making your parameterless constructor protected and that should help.

    But please, look at the rest of the guidance.

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

Sidebar

Related Questions

I have developed a project using MVC3 and Code first Entity Framework 4.0 as
I have a project using Entity Framework code first. For various reasons one of
I'm using Entity Framework in my project, and I have the problem that, once
I have been using Entity Framework CTP with Code-First as in this tutorial by
I'm using Entity Framework 4 Code First in my .net MVC 2.0 project and
Using the Entity Framework 4. I have created a Code First database in the
I'm creating a database using entity framework code first and I'm having some issues
I'm using Entity Framework 4.3 with code first and manual migrations. I'm trying to
I am using Entity Framework 4.1 code first and ASP.NET MVC 3 and I
We've got a project built on Winforms and Entity Framework 4.2 (code-first) and SQLServer

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.