title: How to avoid circular references with AutoMapper?
body: <p>I have the following models (and corresponding DTOs):</p>
  
  <pre><code>public class Link
  {
      public int Id {get; set;}
      public int FirstLinkId {get; set;}
      public int SecondLinkId {get; set;}
      public virtual Link FirstLink {get; set;}
      public virtual Link SecondLInk {get; set;}
  }
  
  public class OtherObject
  {
      public int Id {get; set;}
      public int LinkId {get; set;}
      public string Name {get; set;}
      public virtual Link Link {get; set;}
  }
  </code></pre>
  
  <p>In my scenario, I can have a <code>Link</code> object where <code>FirstLink</code> and/or <code>SecondLink</code> can be null, references to other objects, or references to the same object.</p>
  
  <p>Now I want to load an <code>OtherObject</code> entity from the db using EF. I load the entity itself and also the <code>Link</code> object associated with it. This is done perfectly by EF.</p>
  
  <p>In this particular case, both <code>FirstLink</code> and <code>SecondLink</code> are the same as <code>Link</code>, therefore, when automapping from model to dto it just keeps on mapping into oblivion.</p>
  
  <p>My mapping is:</p>
  
  <pre><code>Mapper.CreateMap&lt;OtherObject, OtherObjectDto&gt;().Bidirectional()
        .ForMember(model =&gt; model.LinkId, option =&gt; option.Ignore());
  </code></pre>
  
  <p>where Bidirectional() is this extension:</p>
  
  <pre><code>public static IMappingExpression&lt;TDestination, TSource&gt; Bidirectional&lt;TSource, TDestination&gt;(this IMappingExpression&lt;TSource, TDestination&gt; expression)
  {
      return Mapper.CreateMap&lt;TDestination, TSource&gt;();
  }
  </code></pre>
  
  <p>Is there way to tell Automapper not to map further down the tree in this case?</p>