title: AutoMapper - mapping child collections in viewmodel
body: <p>I have a viewmodel that needs to display a certain <code>IEnumerable</code> field as semicolon-separated textbox. At first I thought of using <code>DefaultModelBinder</code> to transform it, but I had trouble thinking how to achieve it in both directions (dto &lt;-> viewmodel).</p>
  
  <p>Nicknames is the field I'm trying to display as one textbox separated by semicolon.</p>
  
  <pre><code>public class Parent
  {
      public IEnumerable&lt;Child&gt; Children { get; set; }
  }
  
  public class Child
  {
      public IEnumerable&lt;string&gt; Nicknames { get; set; }
  }
  </code></pre>
  
  <p>So I decided to try AutoMapper, I created two ViewModels:</p>
  
  <pre><code>public class ParentViewModel
  {
      public IEnumerable&lt;ChildViewModel&gt; Children { get; set; }
  }
  
  public class ChildViewModel
  {
      public string Nicknames { get; set; }
  }
  </code></pre>
  
  <p>Then, I created mappings, like this for the children (omitted the other-way conversion for brevity)</p>
  
  <pre><code>Mapper.CreateMap&lt;Child, ChildViewModel&gt;().ForMember(
  d =&gt; d.Nicknames, o =&gt; o.ResolveUsing&lt;ListToStringConverter&gt;().FromMember(s =&gt; s.Nicknames);
  </code></pre>
  
  <p>Then, for the parent, created a naive map (again, omitted the other-way)</p>
  
  <pre><code>Mapper.CreateMap&lt;Parent, ParentViewModel&gt;();
  </code></pre>
  
  <p>I truly expected the child mappings occur automatically, but they don't, I've already created too much "proper" code to solve a really simple problem which in any other simpler/older non-MVC environment, I'd be done with a long time ago :) How can I proceed and tell AutoMapper to transform the children without writing another "children member resolver".</p>
  
  <p>Have I overthought this and there's a simpler way?</p>
  
  <p>Thank you!</p>