title: AutoMapper: Merging values of items in a collection from one instance to another
body: <p>I am trying to figure out how to merge two complex object instances using AutoMapper. The parent object has a property which is a collection of child objects:</p>
  
  <pre><code>public class Parent
  {
      public List&lt;Child&gt; Children { get; set; }
  }
  
  public class Child
  {
      public string A { get; set; }
      public string B { get; set; }
      public string C { get; set; }
  }
  </code></pre>
  
  <p>I have two instances of <code>Parent</code>:</p>
  
  <pre><code>var parentOne = new Parent()
  {
      Children = new List&lt;Child&gt;() { new Child() { A = "A", B = "B", C = "C" } }
  };
  
  var parentTwo = new Parent()
  {
      Children = new List&lt;Child&gt;() { new Child() { C = "Updated value" } }
  };
  </code></pre>
  
  <p>I would like to be able to merge values from <code>parentOne</code> to <code>parentTwo</code>, without overwriting the value of <code>C</code> in <code>parentTwo</code>. The maps I have created are as follows:</p>
  
  <pre><code>Mapper.CreateMap&lt;Parent, Parent&gt;()
      .ForMember(parent =&gt; parent.Children, opt =&gt; opt.UseDestinationValue());
  
  Mapper.CreateMap&lt;Child, Child&gt;()
      .ForMember(child =&gt; child.C, opt =&gt; opt.Ignore());
  
  Mapper.Map(parentOne, parentTwo);
  </code></pre>
  
  <p>As I understand it, AutoMapper will create new instances of complex properties unless you use the <code>UseDestinationValue()</code> option. However, after executing the code above, <code>parentTwo.C</code> equals <code>"C"</code> instead of <code>"Updated value"</code>.</p>
  
  <p>It looks to me like it's keeping the instance of <code>List&lt;Child&gt;</code>, but it is creating new instances of <code>Child</code> <em>within</em> the List. Unfortunately, I'm struggling to come up with a map that will keep each instance of <code>Child</code> as well.</p>
  
  <p>Any help would be much appreciated!</p>