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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:21:46+00:00 2026-05-10T19:21:46+00:00

Is there a way to disable LINQ’s object tracking features, without also disabling lazy-loaded

  • 0

Is there a way to disable LINQ’s object tracking features, without also disabling lazy-loaded child associations?

I’m using LINQ2SQL in a set of integration tests. I’m only using LINQ to verify changes in the database, so I want it to act like a simple data access layer rather than a full ORM. To do this,I set set the data context’s ObjectTrackingEnabled property to false to prevent LINQ from caching data. This works fine, except that it breaks associations between entities.

For instance, assume two tables WIDGET and CATEGORY, with a FK relationship between them. With object tracking enabled, widgetInstance.CATEGORY is correctly lazy-loaded. With object tracking disabled, nothing is lazy loaded and the CATEGORY property is always null.

How do I prevent LINQ from caching data, without also preventing lazy-loading?

UPDATE: Here’s a link to the MSDN page referenced by the answer. Further research also turned up that I can use LoadWith to do eager loading of child data. In my case I just want the data, so eager loading is fine.

  • 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. 2026-05-10T19:21:47+00:00Added an answer on May 10, 2026 at 7:21 pm

    According to MSDN:

    Deferred loading requires object tracking. Only the following three modes are valid:

    ObjectTrackingEnabled = false. DeferredLoadingEnabled is ignored and inferred to be false. This behavior corresponds to a read-only DataContext.

    ObjectTrackingEnabled = true. DeferredLoadingEnabled = false. This situation corresponds to a DataContext that allows users to load an object graph by using LoadWith directives, but it does not enable deferred loading.

    Both are set to true. This is the default.

    You either have to enable object tracking and detach entities (which is doable since you’re running tests, I guess, otherwise it pretty much troublesome to detach every single entity of another entity of…), or use DataLoadOptions.LoadWith() or AssociateWith() to eager-load the relationships.

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

Sidebar

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.