title: AutoMapper avoid nested loops
body: <p>I am currently using Automapper to map from my domain model to DTO. Inside my 
  Domain model I have 3 bool properties (<code>IsHomeowner</code>, <code>IsTenant</code>, <code>IsLivingWithParents</code>) which are used to set the value of a property
  inside the ViewModel i.e. <code>PersonDTO</code> called <code>LivingStatus</code></p>
  
  <p>However, to get to my end result I am having to loop through the <code>Person</code> model, create Dictionary
  to store my values and then using <code>AfterMap</code> create a nested loop and set the value inside there. </p>
  
  <p>Although it works but is not an ideal solution because it is more likely to create memory leaks as data increases 
  in Size.</p>
  
  <p>So was wondering if there is anything in AutoMapper to avoid this?</p>
  
  <p>Here is my code</p>
  
  <p><strong>View Model</strong></p>
  
  <pre><code>public class PersonDTO{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string Surname { get; set; }
    public Status LivingStatus { get; set; }
  }
  </code></pre>
  
  <p><strong>Domain Model</strong></p>
  
  <pre><code>public class Person{
     public int Id { get; set; }
     public string FirstName { get; set; }
     public string Surname { get; set; }
     public bool IsHomeOwner { get; set; }
     public bool IsTenant { get; set; }
     public bool IsLivingWithParents { get; set; }
  }
  
  public enum Status{
     Homeowner=1,
     Tenant=2,
     LivingWithParents=3
  }
  </code></pre>
  
  <pre><code>public List&lt;PersonDTO&gt; GetEmployee(List&lt;Person&gt; persons)
  {
     var livingStatus = new Dictionary&lt;int, Status&gt;();
     foreach (var person in persons)
     {
         if (person.IsHomeOwner)
         {
            livingStatus.Add(person.Id, Status.Homeowner);
         }
         else if (person.IsTenant)
         {
            livingStatus.Add(person.Id, Status.Tenant);
         }
         else
         {
            livingStatus.Add(person.Id, Status.LivingWithParents);
         }
     }
  
     return _mapper.Map&lt;List&lt;Person&gt;, List&lt;PersonDTO&gt;&gt;(persons, opts =&gt; opts.AfterMap((src, dest) { 
     foreach(var person in dest)
     {
       person.LivingStatus = livingStatus.Single(x =&gt; x.Key == person.Id).Value;
     }
     }));
  }
  </code></pre>