title: EF4 Self-Tracking entities and WCF serialization creates stack overflow
body: <p>I try to get above configuration working, but with no luck.</p>
  
  <p><strong>Step 1)</strong></p>
  
  <p>I started a new solution with a <em>WCF Service Application</em> project.</p>
  
  <p><strong>Step 2)</strong></p>
  
  <p>In this project, I added an edmx file and create a very simple model:<br>
  Entity <strong><em>Parent</em></strong> with <em>Id</em> and <em>DisplayName</em><br>
  Entity <strong><em>Child</em></strong> with <em>Id</em> and <em>ChildDisplayName</em><br>
  Association from <em>Parent</em> to <em>Child</em>, <em>1-to-m</em>, resulting in NavigationProperties on both entities.<br>
  I generatedthe database without any problems. After generation, I inserted one <em>Parent</em> object with two related <em>Child</em> objects manually to the database.</p>
  
  <p><strong>Step 3)</strong></p>
  
  <p>I added the code generation, using the <strong><em>ADO.NET Self-Tracking Entity Generator</em></strong>.
  I know that this should be done in diffrent assemblies, but to make it straight and easy, I put it all to the same project (the WCF project)</p>
  
  <p><strong>Step 4)</strong></p>
  
  <p>I just changed the IService Interface to create a simple get</p>
  
  <pre><code>    [OperationContract]
      Parent GetRootData(Int32 Id);
  </code></pre>
  
  <p>In the corresponding implementation, I take an <em>Page</em> object from the context and return it:</p>
  
  <pre><code>    using (PpjSteContainer _context = new PpjSteContainer() )
      {
          return _context.ParentSet.Include("Child").Single(x =&gt; x.Id == Id);
      }
  </code></pre>
  
  <p><strong>Problem:</strong></p>
  
  <p>If I now run this project (the Service1.svc is start page), VS2010 automatically generates the test client to invoke the service. But once I invoke the service, I get an StackOverflowException! Debugging on the server side looks ok until it returns the object graph.</p>
  
  <p>If I remove the <strong>Include("Child")</strong> everything is ok, but of course the <em>Child</em> objects are missing now.<br>
  I have no idea what I'm missing. I read a lot of howto's and guides, but all do it the way I did it (at least that's what I think)...<br>
  I tried the School example <a href="http://msdn.microsoft.com/en-us/library/ee789839.aspx" rel="nofollow">here</a>, but this does not work for me as it seems the database generation and the coding in the example does not match.</p>
  
  <p>So, I would much appreciate if someone could guide me how to make this work.</p>
  
  <p><strong>P.S.</strong></p>
  
  <ul>
  <li>Yes, all Entity-Classes are marked "[DataContract(IsReference = true)]"</li>
  <li>Lazy-Loading is set to "false" in the edmx file</li>
  </ul>
  
  <p><strong>Edit:</strong><br>
  I changed the WCF to be hosted in a console app and no longer in IIS. Of course then I had to write my own little test client.<br>
  Funny enough, now everything's working.
  I of course have no idea why, but at least for my testing this is a solution...  </p>