title: AutoMapper - one to many mapping
body: <p>I am having problems in <strong>mapping one source object with a nested list to multiple destination objects</strong>. As of project restrictions I can only adapt parts of the code. I am using AutoMapper 5.1.</p>
  
  <pre><code>/// no changes possible
  namespace Source
  {
      class Person
      {
          public string Name { get; set; }
          public List&lt;Car&gt; Cars { get; set; }
  
          public Person()
          {
              Cars = new List&lt;Car&gt;();
          }
      }
  
      class Car
      {
          public string NumberPlate { get; set; }
      }
  }
  
  /// no changes possible
  namespace Destination
  {
      class PersonCar
      {
          public string Name { get; set; }
          public string NumberPlate { get; set; }
      }
  }
  
  /// Demo Consolen Application
  static void Main(string[] args)
  {
      #region init data
      Person person = new Person();
      for (int i = 0; i &lt; 10; i++)
      {
          person.Cars.Add(new Source.Car() { NumberPlate = "W-100" + i });
      }
      #endregion
  
      /// goal is to map from one person object o a list of PersonCars            
      Mapper.Initialize(
          cfg =&gt; cfg.CreateMap&lt;Person, List&lt;PersonCar&gt;&gt;()
              /// this part does not work - and currently I am stuck here
              .ForMember(p =&gt; 
              {
                  List&lt;PersonCar&gt; personCars = new List&lt;PersonCar&gt;();
  
                  foreach (Car car in p.Cars)
                  {
                      PersonCar personCar = new PersonCar();
                      personCar.Name = p.Name;
                      personCar.NumberPlate = car.NumberPlate;
                      personCars.Add(personCar);
                  }
                  return personCars;
              })
      );
  
      // no changes possible
      List&lt;PersonCar&gt; result = Mapper.Map&lt;Person, List&lt;PersonCar&gt;&gt;(person);
  }
  </code></pre>
  
  <p>} </p>
  
  <p>Right now I am stuck on defining a proper mapping for this problem. Although I did a (ugly!!) mapping at workt (left code there .. <em>facepalm</em>  ) I am sure there must be a simple solution for this problem.</p>
  
  <p>Any help would be appreciated!</p>