title: Using navigation properties in entity framework code first
body: <p>Context:</p>
  
  <ul>
  <li>Code First, Entity Framework 4.3.1;</li>
  <li>User ---- Topic, <strong>1 to Many</strong> relation;</li>
  <li><code>User</code> with <code>public virtual ICollection&lt;Topic&gt; CreatedTopics</code> Navigation Property(Lazy Loading);</li>
  <li><code>Topic</code> with <code>public virtual User Creator</code> Navigation Property;</li>
  <li><code>DataServiceController : DbDataController&lt;DefaultDbContext&gt;</code>, Web API beta, ASP.NET MVC 4 Beta , Single Page Application;</li>
  <li>System.Json for Json serialization;</li>
  <li><p>Web API Action:</p>
  
  <pre><code>public IQueryable&lt;Topic&gt; GetTopics()
  {
      // return DbContext.Topics;                   // OK
      return DbContext.Topics.Include("Creator");   //With Exception
  }
  </code></pre></li>
  <li><p>Result: <strong>"an unhandled microsoft .net framework exception occurred in w3wp.exe"</strong></p></li>
  </ul>
  
  <p>The Problem here seems to be: I should not <strong>Add Navigation Property in both Entities</strong>(Cause Circular Reference?), and if I delete the <code>CreatedTopics</code> Navigation Property in <code>User</code> Class, It will be OK again.</p>
  
  <p>So, <em>In a similar Context like listed above</em>, Here are my questions:</p>
  
  <ol>
  <li>How to deal with Navigation Properties in the situation of <strong>1 to Many</strong> relation;</li>
  <li>Further more, how about a <strong>Many to Many</strong> relation, do i have to divide it into two <strong>1 to Many</strong> relations;</li>
  <li>What is the Best Practices and Precautions of using Navigation Properties?</li>
  </ol>
  
  <p>I Have read many related posts, but still not clear enough :(,</p>
  
  <p>Thanks for any help!</p>
  
  <p>Dean</p>