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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:16:39+00:00 2026-06-17T08:16:39+00:00

I need to retrieve a large hierarchy of entities from my database, with many

  • 0

I need to retrieve a large hierarchy of entities from my database, with many relationships. Rather than create one giant queries with many Includes, I’ve read that it’s possible to use a number of smaller queries to fetch different parts of the hierarchy, then EF somehow glues everything together using something called “association fixup”. However I’m struggling to get it to work. (I’m using EF5 and POCO by the way).

As a simple example, I’m trying to retrieve a Customer and all their related Orders using the “fixup” technique. This is what I’m doing in my BLL tier:-

var customer = context.Customers
    .Where(o => o.Id == requestedCustomerId).SingleOrDefault();

customer.Orders = context.Orders
    .Where(o => o.CustomerId = requestedCustomerId).ToList();

When I examine the customer entity returned to the UI tier, customer.Orders gives an ObjectDisposedException. What am I doing wrong?

As a further example of how fixup would be used, how would I populate the Orders’ related OrderLines (either in a separate query, or as part of the second query above)? And what if the OrderLine entity had a ProductCategory parent entity – how would I populate these?

Update

I’ve just tried the following, which works:-

var orders = context.Orders
    .Where(o => o.CustomerId = requestedCustomerId).ToList();

var customer = context.Customers
    .Where(o => o.Id == requestedCustomerId)
    .Include("Orders")
    .SingleOrDefault();

Am I right in saying that the second query won’t fetch Orders from the database again, and EF will associate those retrieved by the previous query (even though they are just sitting in some arbitrary variable)?

  • 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-17T08:16:40+00:00Added an answer on June 17, 2026 at 8:16 am

    The ObjectDisposed exception is probably because you have lazy loading turned on and you are disposing your context before trying to access customer.Orders. I don’t like lazy loading, so I always turn it off:

    // in your context constructor:
    this.Configuration.LazyLoadingEnabled = false;
    

    Your original example should now work.


    In your update, you are eagerly loading Customer.Orders with the Include clause. This means EF is getting this data from the database using a join when it gets the Customer record.


    EDIT:

    A DbContext “remembers” every object it has seen, where an object is basically a database row.

    If you load the Orders associated with a particular Customer then the context remembers those Order objects.

    When you subsequently fetch the Customer object ( without .Include( "Orders" ) ), EF is smart enough to attach the Order objects you previously fetched to the Customer object.

    It can do this, because the Order objects have a CustomerId, so when you get that Customer object it can look at its CustomerId property and add the Order objects to the Customer.Orders collection.

    It will only attach the Orders it knows about, so if you haven’t previously loaded all the associated Order records for some reason, EF will just attach those it has seen.

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

Sidebar

Related Questions

I need to retrieve from the database a few large wave files and would
I need to retrieve random rows from SQL Server database. I am looking for
If I have a large html page I retrieve from a database, and it
I need to retrieve from an Application Server (JBoss) a large file (gigabytes) and
I need to get rather complicate JSON data from (large) JSON file into a
If I need to retrieve a large string from a DB, Is it faster
Hi I'm new to Oracle 10g. I need retrieve the all the sublist from
I need to retrieve a value from a website (can vary and I have
I need to retrieve information from two separate models which are similar but not
i need to retrieve the page title from an URL i already have using

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.