title: Self referencing loop detected
body: <p>I have read a lot of previous solutions for this problem but none worked for me.</p>
  
  <p>I have a circular relation between Event and User object:</p>
  
  <pre><code>public class Event : EntityData
  {
      [Required]
      [ForeignKey("Creator")]
      public string CreatorId { get; set; }
      public User Creator { get; set; }
  
      [InverseProperty("ParticipantIn")]
      public virtual ICollection&lt;User&gt; Participants { get; set; }
  
      [InverseProperty("ManagerIn")]
      public virtual ICollection&lt;User&gt; Managers { get; set; }
  }
  </code></pre>
  
  <p>As you can see I have three references to User from this class: event creator, list of managers, and list of participants.</p>
  
  <p>The user class contains references to Event as well:</p>
  
  <pre><code>public class User: EntityData
  {
      [InverseProperty("Participants")]
      public virtual ICollection&lt;Event&gt; ParticipantIn { get; set; }
  
      [InverseProperty("Managers")]
      public virtual ICollection&lt;Event&gt; ManagerIn { get; set; }
  }
  </code></pre>
  
  <p>Now, the issue is that when I try to serialize an event, like in my createEvent function, it tells me that there is a self referencing loop, that is because when the event is created, I am adding it to the creator's 'ManagerIn' Collection.</p>
  
  <p>That line causes Event->Creator->ManagerIn->Event->Creator->..... LOOP</p>
  
  <p>I tried anything, I also had a version of this code with public virtual User Creator, in order to make it load lazily..</p>
  
  <p>For now, my solution is very not elegant, before returning the event to the client I am performing:</p>
  
  <pre><code>event.Creator = null;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>event.Managers = null;
  </code></pre>
  
  <p>in order to avoid a self referencing loop.</p>
  
  <p>What is the right way to solve this kind of problem?</p>
  
  <p>Thanks in advance, 
  Liran!</p>