title: How to use automapper to map Parent of source type into a collection of destination type?
body: <p>I have these classes:</p>
  
  <pre><code>public class Source 
  {
      public string ID { get; set; }
      public int Age Name { get; set; }
      public virtual ICollection&lt;SourceChild&gt; SourceChildren { get; set; }
  }
  
  public class SourceChild 
  {
      public string Name { get; set; }
      public string Language { get; set; }
      public string SourceId { get; set; }
      public virtual Source Source { get; set; }
  }
  
  public class Destination
  {
      public int Age { get; set; }
      public string Name { get; set; }
      public string Language { get; set; }
      public string Id { get; set; }
  }
  </code></pre>
  
  <p>I was mapping these classes using these mappings:</p>
  
  <pre><code>        Mapper.CreateMap&lt;SourceChild, Destination&gt;()
              .ForMember(item =&gt; item.ID, property =&gt; property.MapFrom(item =&gt; item.SourceId))
              .ForMember(item =&gt; item.Age, property =&gt; property.MapFrom(item =&gt; item.Source.Age));
  </code></pre>
  
  <p>Automapper maps the other two properties automatically. So everything works fine if I try to map <code>SourceChild</code> into <code>Destination</code> type. However now I have another class using source and destination types:</p>
  
  <pre><code>public class SourceUser 
  {
      public string ID { get; set; }
      public virtual Source Source { get; set; }
  }
  
  public class DestinationUser
  {
      public string Id { get; set; }
      public List&lt;Destination&gt; Destinations { get; set; } 
  }
  </code></pre>
  
  <p>To illustrate the situation better here is short description on the classes: I have <code>Source</code> object and <code>SourceChild</code> children objects. <code>SourceChild</code> objects contain information in different languages. When I map Source into <code>Destination</code> I want to input the Source object and receive output of a collection of destination objects. For each <code>SourceChild</code> object, <code>Source</code> object had, there should be one <code>Destination</code> object.<code>SourceUser</code> simply refers to <code>Source</code> with a 1-many relation. <code>DestinationUser</code> had a many - many retion with <code>Destination</code> class. In other words each <code>DestinationUser</code> has a list of all <code>Destinations</code> in all languages. So having all this in mind let's get back to the code.</p>
  
  <p>I have had some luck in writing the code I need. I have come up with this:</p>
  
  <pre><code> Mapper.CreateMap&lt;SourceUser, DestinationUser&gt;()
                  .AfterMap((source, destination) =&gt; Mapper.Map&lt;Source, List&lt;Destination&gt;&gt;(source.Source));
  
      Mapper.CreateMap&lt;Source, List&lt;Destination&gt;&gt;()
                      .AfterMap((source, destination) =&gt; Mapper.Map&lt;List&lt;SourceChild&gt;, List&lt;Destination&gt;&gt;(source.SourceChildren.ToList(), destination));
  </code></pre>
  
  <p>This works ALMOST well enough, there is one IF though. I am using queryable extensions to process the mapping. When I retrieve a collection of <code>DestinationUsers</code>, none of them have the property <code>Destinations</code> mapped. It appears as null. However, if I do the mapping manually like this:</p>
  
  <pre><code>SourceUser SourceUser = Db.GetSourceUser();
  DestinationUser DestUser = Db.GetDestinationUser();
  DestUser.Destinations = Mapper.Map&lt;List&lt;Destination&gt;&gt;(SourceUser.Source);
  </code></pre>
  
  <p>everythign works fine. A list fo DestinationUsers is mapped from the instance of Source. </p>
  
  <p>is it possible to avoid manually calling the latter <code>Mapper.Map()</code> call? Also bear in mind, that the List Destinations may be changed into any other collection. I just want to have a Destination object for each <code>SourceChild</code> object <code>Source</code> had. </p>