title: ef4 cause Circular reference in web service
body: <p>I have a Reason object:  </p>
  
  <pre><code>public class Reason
  {
      public virtual long Id { get; set; }
      public virtual string Name { get; set; }
      public virtual Company Company {get;set;}
  }
  </code></pre>
  
  <p>I am using entity framework 4 and Company is navigation property to Company.<br>
  I also use webservices in order to return data to the client.<br>
  I have web method that returns Reasons:</p>
  
  <pre><code>  [WebMethod]
      public Reason[] GetCallReasons()
      {
          IReasonRepository rep =
              ObjectFactory.GetInstance&lt;IReasonRepository&gt;();
          return rep.GetReasonsList().ToArray();
      }
  </code></pre>
  
  <p>Because of the ef4 I get the following exception for executing the web method:</p>
  
  <pre><code>A circular reference was detected while serializing an object of type 'System.Data.Entity.DynamicProxies.Reason_24A0E4BBE02EE6BC2CF30BB56CFCB670C7D9D96D03D40AF4D174B89C9D3C5537'
  </code></pre>
  
  <p>The problem accurs because ef4 adds property that can't be serialized:
  <img src="https://i.stack.imgur.com/lZhur.png" alt="Image of the watch panel on rep.GetReasonsList().ToArray()"></p>
  
  <p>In order to solve this and eliminate the error, I can disable the navigation property by not making it virtual or by remove the navigation property. But I neet it and want to use the lazy loading feature.</p>
  
  <p>I also can write spesific serializer for Reason but I have many many classes the I used in my web-services and write a serializer for all of them is a lot of work.</p>
  
  <p>How can I solve this exception?..</p>