title: EF6: How to avoid circular reference?
body: <p>What are the possibilities to avoid circular reference with Entity Framework 6 during JSON serialization with ASP.NET Web API?</p>
  
  <p>I generated a edmx (Entity Data Model) file for Entity Framework 6, database first. I try to build an API with ASP.NET Web API. When I try to return my JSON object in my controllers I get a runtime exception of serialization because of circular reference.</p>
  
  <p>Indeed when I double check my database and my entities I see one of my entity contains a list another entity that contain a list of my previous entity. let say I have a book entity that contains authors and each author entity contains a list of books. This is something common with relative database but impossible to resolve in JSON serialization (or impossible to resolve for the .NET serializer).</p>
  
  <p>I don't want to change my database but I'm ready to break the wrong list into my entities or edmx file. What can I do?</p>
  
  <p><strong>What I have tried:</strong></p>
  
  <p>I already tried the solution that consist of creating new models or entities and using a mapping tool (<a href="http://www.codeproject.com/Articles/292970/Avoiding-Circular-Reference-for-Entity-in-JSON-Ser" rel="nofollow">http://www.codeproject.com/Articles/292970/Avoiding-Circular-Reference-for-Entity-in-JSON-Ser</a> or the solution explained by by Shawn Wildermuth on Pluralsight). </p>
  
  <p>This solution sounds more like a workaround than a real solution. It should exist something in edmx file or in Entity Framework to tell the JSON serializer what can cause circular reference, what can and must be serialized and what cannot be serialized, right?</p>