title: Entity framework 6 many to many code first eager loading gives recursive result
body: <p>I'm trying to learn Entity Framework 6 code first using VS 2013.</p>
  
  <p>I'm doing the exact same thing as in this question: <a href="https://stackoverflow.com/questions/5851169/how-to-eagerly-load-a-many-to-many-relationship-with-the-entity-framework-code-f">How to eagerly load a many to many relationship with the entity framework code first?</a></p>
  
  <p>Using the same setup</p>
  
  <pre><code>public class Student
  {
      public int Id {get;set}
      public string FullName {get;set;}
      public virtual ICollection&lt;Course&gt; Courses {get;set;}
  }
  
  public class Course
  {
      public int Id {get;set;}
      public string FullName {get;set;}
      public virtual ICollection&lt;Student&gt; Students {get;set;}
  }
  </code></pre>
  
  <p>And the answer</p>
  
  <pre><code>var allStudents = context.Students.Include( s =&gt; s.Courses);
  </code></pre>
  
  <p>But when debugging I get a recursive result.
  Every Student contains a list of Courses and those Courses contains a list of Students, which contains Courses, that contains Students and so on....</p>
  
  <p>The same thing without using the method <code>.Include(...</code></p>
  
  <pre><code>var allStudents = context.Students;
  </code></pre>
  
  <p>I'm using this in a scaffolded MVC 5 ApiController which throws:</p>
  
  <blockquote>
    <p>System.Runtime.Serialization.SerializationException</p>
  </blockquote>
  
  <p>Removing <code>Virtual</code> from the Models and still using <code>.Include(...</code> throws:</p>
  
  <blockquote>
    <p>Object graph for type 'SchoolEF.Models.Course' contains cycles
    and cannot be serialized if reference tracking is disabled.</p>
  </blockquote>
  
  <p>I guess i have not fully understood how to do eager loading and how to use the .Include() method.</p>