Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you disable change tracking by setting the <code>NoTracking</code> merge option you save the performance costs of attaching objects to the contexts but on the other hand you also lose identity management.</p> <p>This means that potentially much more objects - many with the same key - will be materialized. </p> <p>Example: Suppose you have a <code>User</code> entity with a <code>Roles</code> 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...</p> <pre><code>var users = context.Users.Include("Roles").ToList(); </code></pre> <p>...the number of materialized and instantiated objects depends on the merge option:</p> <ul> <li><p>If you don't use <code>NoTracking</code> 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 <code>Roles</code> collection.</p></li> <li><p>If you use <code>NoTracking</code> 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.</p></li> </ul> <p>Object materialization is classified with <a href="http://msdn.microsoft.com/en-us/library/cc853327.aspx" rel="noreferrer">"moderate" performace costs</a>:</p> <blockquote> <p><strong>Operation: Materializing the objects</strong> <br /> <strong>Relative Cost: Moderate</strong> <br /> <strong>Frequency: Once for each object that a query returns.</strong> <br /> <br /> <strong>Comments:</strong> 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. <strong>If the object already exists in the ObjectContext and the query uses the <em>AppendOnly</em> or <em>PreserveChanges</em> merge options, this stage does not affect performance.</strong></p> </blockquote> <p>In other words: If the query uses the <code>NoTracking</code> merge option, this stage <strong>does affect performance</strong> 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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload