title: Returning Entity Data Model Entities as JSON data
body: <p>I noticed people wrote about this circular reference problem quite a bit before but no solution was ever posted. </p>
  
  <p>I'm talking about this error:
  "A circular reference was detected while serializing an object of type 'DocInvoice.Models.Clients'."</p>
  
  <p>Has anyone tried serializing it to JSON with Json.NET library?</p>
  
  <p>If I have Linq to entities queries, is my only option to hand code entity properties and leave out those that are Navigational properties? Because those are the ones making problems..</p>
  
  <p>It is annoying though because you have to hand write like dozens (or more) entity properties in Linq "new" statement. For instance, if I want all the properties I can do this but it results in circular reference error:      </p>
  
  <pre><code>var clients = from client in edmx.Clients
      from postcode in edmx.PostCodes
      where (client.client_firstname.StartsWith(q) ||
                     client.client_lastname.StartsWith(q)) &amp;&amp; 
                     postcode.postcode == client.PostCodes.postcode
      select new {client, postcode};
  </code></pre>
  
  <p>the only other option is:</p>
  
  <pre><code>select new { client.client_id, 
               client.client_firstname, 
               ....., ... , 
               postcode.postcode
             }; ...
  </code></pre>