title: Return plain objects in entity framework for serialization
body: <p>I have been trying out both Linq to Sql and EF in my ASP.NET MVC application. After switching to EF I realized my XML/JSON serialization output has extra cruft.</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;EntityKey&gt;
      &lt;EntitySetName&gt;Persons&lt;/EntitySetName&gt;
      &lt;EntityContainerName&gt;PersonEntities&lt;/EntityContainerName&gt;
      &lt;EntityKeyValues&gt;
        &lt;EntityKeyMember&gt;
          &lt;Key&gt;Id&lt;/Key&gt;
          &lt;Value xsi:type="xsd:int"&gt;1&lt;/Value&gt;
        &lt;/EntityKeyMember&gt;
      &lt;/EntityKeyValues&gt;
    &lt;/EntityKey&gt;
    &lt;Id&gt;1&lt;/Id&gt;
    &lt;Name&gt;John&lt;/Name&gt;
  &lt;/Test&gt;
  </code></pre>
  
  <p>JSON:</p>
  
  <pre><code>{"Id":1,"Name":"John","EntityState":2,"EntityKey"{"EntitySetName":"Persons","EntityContainerName":"PersonEntities","EntityKeyValues":[{"Key":"Id","Value":1}],"IsTemporary":false}}
  </code></pre>
  
  <p>Instead I would just like my output to be:</p>
  
  <pre><code>{"Id":1, "Name":"John"}
  </code></pre>
  
  <p>My EF query to retrieve the object is:</p>
  
  <pre><code>Tests.First(t =&gt; t.Id == testId);
  </code></pre>