title: Automapper map child list with from same type
body: <p>I have entities that may have children and their children may have children and so on...
  When I get database models all entities are OK with correct children and parent. But the problem comes when I want to map to view model:
  Is there any possible way to map models from database like this?</p>
  
  
  
  <pre><code>// database model code first
  public class Tomato
  {
      public int Id { get; set; }
  
      public string Name { get; set; }
  
      public int? ParentId { get; set; }
  
      public virtual Tomato Parent { get; set; }
  
      public ICollection&lt;Tomato&gt; Children { get; set; }
  }
  
  // mvc view model
  public class TomatoViewModel
  {
      public int Id { get; set; }
  
      public string Name { get; set; }
  
      public int? ParentId { get; set; }
  
      public ICollection&lt;TomatoViewModel&gt; Children { get; set; }
  }
  </code></pre>
  
  <p>Configured <code>configuration.CreateMap&lt;Tomato, TomatoModel&gt;()</code> but throws an <code>StackOverflowException</code> when try to bind child elements. Tried with</p>
  
  <pre><code>configuration.CreateMap&lt;Tomato, TomatoViewModel&gt;().ForMember( t =&gt; t.Children,
                  options =&gt; options.Condition(context =&gt; (context.SourceValue as Tomato).ParentId == this.Id));
  // this.Id refers to TomatoViewModel.Id
  </code></pre>
  
  <p>Update: in my controller class:</p>
  
  <pre><code>var models = foodIngredientsService.GetAllTomatoes().Where(t =&gt; t.ParentId == null).To&lt;TomatoModel&gt;().ToList();
  </code></pre>
  
  <p><strong>Second Question</strong>: how to use second overload of  <code>options.Condition(Func&lt;TomatoModel, bool&gt; func)</code> ??</p>