title: Serialize one to many relationships in Json.net
body: <p>I am using the Entity Framework code first for data access and I have a Company class which has a collection of Employees. The Employee class also has a Company property.</p>
  
  <p>I would like to be able to serialize a Company and include the list of employees in the serialization.</p>
  
  <p>Here is Company:</p>
  
  <pre><code>public class Company
  {
  public long Id { get; set; }
  public string Name { get; set; }
  public DateTime? Established { get; set; }
  
  public virtual IList&lt;Employee&gt; Employees { get; set; }
  
  public DateTime? DateCreated { get; set; }
  public DateTime? DateUpdated { get; set; }
  }
  </code></pre>
  
  <p>Here is Employee</p>
  
  <pre><code>public class Employee
  {
  public long Id { get; set; }
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public int Age { get; set; }
  
  public virtual Company Company { get; set; }
  
  public DateTime? DateCreated { get; set; }
  public DateTime? DateUpdated { get; set; }
  }
  </code></pre>
  
  <p>I get a serialization Exception "Self referencing loop detected for type" when I try to serialize a Company object.</p>
  
  <p>Thanks.</p>