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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:42:05+00:00 2026-05-25T15:42:05+00:00

In my app, I frequently fetch some data from database, serialize it automatically and

  • 0

In my app, I frequently fetch some data from database, serialize it automatically and then send it somewhere.

Database structure is quite complicated, but let’s assume, that I have three relations, A, B and C, where B and C have foreign keys pointing to A. Thus, it is possible to navigate between these relations using Navigation Properties (and I like this feature, I don’t want to disable it).

Data fetching is done with Entity Framework, so I just linq it from some ObjectContext. There is a MergeOptions.NoTracking option set.

My data serialization checks every property and saves it in a specified way. I don’t want to modify this mechanism.

The problem occurs, when I fetch an object from, let’s say, relation A.
I return it from my database layer and pass it to serialization. It tries to access the references to B and C, but while we’re outside the object context, it cannot be done.

I know I can do the following:

AEntry a = db.A.FirstOrDefault(something);
a.BReference.Clear(); //(or .Load())
a.CReference.Clear();
return a;

But I don’t like this solution. I’m looking for something that would allow me to keep the ‘a’ object (or possibly a collection of such objects) unmaterialized as long as possible and I don’t want to bother with every reference (as there may be a lot of them).

Obviously, in this case I don’t care about the content of referred objects (or objects referring to the object I fetch).

I hope my problem is quite clear. Thanks for help.

  • 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-25T15:42:06+00:00Added an answer on May 25, 2026 at 3:42 pm

    I think you want to turn of lazy loading. See this question, either set the ContextOptions property of your ObjectContext:

    context.ContextOptions.LazyLoadingEnabled = false; 
    

    Or, if you’re using an .edmx model, set the LazyLoadingEnabled annotation:

    <EntityContainer Name="MyEntitiesContext" annotation:LazyLoadingEnabled="false"> 
    

    Of course, you will have to make sure that the data you do need is explicitly loaded then (using the Include() method on ObjectQuery.

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

Sidebar

Related Questions

My app is highly data driven, and needs to be frequently updated. Currently the
In our application we are caching some frequently used data. Recently we have developed
My app uses a WebRequest at certain points to get pages from itself. This
Our app (already deployed) is using an Access/Jet database. The upcoming version of our
i get this exception frequently when running my app on tomcat using eclipse: java.lang.OutOfMemoryError:
In my app, I have to draw some images on a view, in real-time,
I am building a web App with mongoDB as the backend. Some of the
I frequently find myself making a dummy console app to test something simple out.
I've got an app that caches a pretty decent amount of data in memory
Here is my situation. I am using two java.util.HashMap to store some frequently used

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.