title: Entity Framework lazy loading with AsNoTracking()
body: <p>We are currently using lazy loading for Entity Framework and running into <code>out of memory exception</code>. The reason why we're running into this exception is because the Linq query loads a lot of data and at latter stages it's using lazy loading to load navigation properties. But because we don't use <code>NoTrackingChanges</code> Entity Framework cache builds up really quickly which results in out of memory error. </p>
  
  <p>My understanding with EF is the we should always use <code>NoTrackingChanges</code> on query unless you want to update the returned object from the query.</p>
  
  <p>I then tested using <code>NoChangeTracking</code>:</p>
  
  <pre><code>var account = _dbcontext.Account
                          .AsNoTracking()
                          .SingleOrDefault(m =&gt; m.id == 1); 
  var contactName = account.Contact.Name
  </code></pre>
  
  <p>but I get the following error:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: When an object is returned with a NoTracking merge option, Load can only be called when the EntityCollection or EntityReference does not contain objects.</p>
  </blockquote>