title: How to serialize into a json from entity?
body: <p>I'm trying to serialize an (Entity Framework 6) entity into json. I am making sure the entry is in memory before serializing via the AsNoTracking() method however I get an error as it cant receive a value form a different table that is referenced in the entry.</p>
  
  <pre><code>Inner Exception: When an object is returned with a NoTracking merge option, Load can only be called when the EntityCollection or EntityReference does not contain objects.
  
  Exception: JsonSerializationException:  Error getting value from 'TABLE_X' on 'System.Data.Entity.DynamicProxies....
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>List&lt;Location&gt; locations = new DbContext().Locations.Where(x =&gt; x.Type == 1).Take(5).AsNoTracking().ToList();
  string s = JsonConvert.SerializeObject(locations, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
  </code></pre>
  
  <p>All I want to do is return a string of the serialized entity. Im not worried about other objects, solely the locations entity.</p>
  
  <p>When I tried disposing of the connection and then json serializing I received the error: <code>The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.</code></p>
  
  <p>I only want to serialize my list, I do not want to return/serialize any foreign dependencies.</p>