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

The Archive Base Latest Questions

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

I have a strange behavior trying to execute a query declaring ObjectQuery MergeOption to

  • 0

I have a strange behavior trying to execute a query declaring ObjectQuery MergeOption to “NoTracking”, in this case entity framework should not attach any entity and not create the relative ObjectStateEntry to track entity state.

The problem is that instead of increase performance it get worse, the same query takes like 10 seconds with default mergeoption (that is AppendingOnly) and more the 1 minutes if I try to specify notracking

Does someone have an explanation for this??

  • 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-29T19:19:13+00:00Added an answer on May 29, 2026 at 7:19 pm

    If you disable change tracking by setting the NoTracking merge option you save the performance costs of attaching objects to the contexts but on the other hand you also lose identity management.

    This means that potentially much more objects – many with the same key – will be materialized.

    Example: Suppose you have a User entity with a Roles collection as navigation property. Also suppose you have 1 million users in the database and all users are in the same 10 roles, i.e. every user has a roles collection with 10 elements. If you run the following query…

    var users = context.Users.Include("Roles").ToList();
    

    …the number of materialized and instantiated objects depends on the merge option:

    • If you don’t use NoTracking you will have 1.000.010 objects in memory, namely 1 million users, but only 10 roles because identity mapping will ensure that only 1 role per key is materialized and attached to the context. The same 10 role instances are used for all user’s Roles collection.

    • If you use NoTracking however, EF won’t attach objects to the context, hence identity management is disabled and you will have 11.000.000 objects in memory: 1 million users and 10 role instances per user, i.e. 10 million role objects. So, you have more than 10 times as many materialized objects as when the objects are attached to the context.

    Object materialization is classified with "moderate" performance costs:

    Operation: Materializing the objects

    Relative Cost: Moderate

    Frequency: Once for each object that a query returns.

    Comments:
    The process of reading the returned DbDataReader object and creating
    objects and setting property values that are based on the values in
    each instance of the DbDataRecord class. If the object already exists
    in the ObjectContext and the query uses the AppendOnly or
    PreserveChanges merge options, this stage does not affect performance.

    In other words: If the query uses the NoTracking merge option, this stage does affect performance and it might be possible that the performance benefits of disabled change tracking are destroyed by the drawbacks of disabled identity management and multiplied object materialization.

    Since EF Core 5.0 there is the additional option ‘NoTrackingWithIdentityResolution’ which disables general tracking but will do identity resolution.

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

Sidebar

Related Questions

I have run into some strange behavior. I am not sure if this should
I have encountered a strange behavior while executing an sql query on the Oracle
I have some strange behavior occurring in an ASP.NET application that I am trying
SPListItem.GetFormattedValue seems to have a strange behavior for DateTime fields. It retrieves the DateTime
I have a very strange behavior with Request.Form . Here are two IIS 7
I have a simple HTML (as HTA) application that shows strange behavior on Windows
I've experienced rather strange behavior of JSTL forEach tag. I have some bean called
In Ruby we have the 'bang' method capitalize! which has the strange behavior of
Why this two functions have the strange behaviour of when I click on thead,
I have strange discarding behavior of struts2 while setting cache option for my image.

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.