title: How can I prevent EF7 from eagerly fixing up navigation properties?
body: <p>I have an issue using EF7 in a web application with which I could use some help. I'm currently using EF7 RC1.</p>
  
  <p>Here are some models that illustrate my problem.</p>
  
  <p><strong>Contact</strong></p>
  
  <pre><code>public class Contact
  {
      public Guid Id { get; set; }
  
      public string Desc { get; set; }
      public ContactType ContactType { get; set; }
  }
  </code></pre>
  
  <p><strong>ContactType</strong></p>
  
  <pre><code>public class ContactType
  {
      public Guid Id { get; set; }
      public string Desc { get; set; }
  
      public ICollection&lt;Contact&gt; Contacts { get; set; }
  }
  </code></pre>
  
  <p>These models are related via Fluent API like this:</p>
  
  <pre><code>modelBuilder.Entity&lt;Contact&gt;(entity =&gt; {
       // abridged for clarity
  
       entity
          .HasOne(c =&gt; c.ContactType)
          .WithMany(ct =&gt; ct.Contacts)
          .IsRequired();                
  });
  </code></pre>
  
  <p>My needs are to be able to retrieve a collection of Contact entities from the database with their ContactType property loaded. EF makes this quite easy:</p>
  
  <pre><code>using(var context = new MyDbContext()) {
      var contacts = await context
          .Contacts
          .Include(c =&gt; c.ContactTypes)
          .Where(/* some search criteria */)
          .ToListAsync();
  }
  </code></pre>
  
  <p>The issue is that in loading the ContactType properties of the Contact entities (which happens due to the call to .Include() in the query), EF also helpfully loads the Contacts property of each ContactType entity, resulting in an infinite chain of Contacts pointing at ContactTypes and ContactTypes pointing at Contacts. I understand why this is the default behavior and that it's helpful in many cases, but my needs are to serialize these entities to JSON and send them down to the client - it's a read-only situation. </p>
  
  <p><strong>My desired behavior is for EF to return a collection of Contacts with loaded (non-null) ContactType properties that have their Contacts property set to null. Is this something EF can do? Is there any way to end up with the object graph I want short of manually nulling out properties I don't want populated?</strong></p>
  
  <p>Things I've tried:</p>
  
  <ul>
  <li>Appending .AsNoTracking() to the EF query (which doesn't seem to stop
  the Contacts property of the ContactType entity from being loaded)</li>
  <li>Telling Json.NET not to serialize infinite reference loops (which is
  required to avoid infinite recursion during serialization, but still
  results in a lot of extra data being serialized)</li>
  </ul>