title: How to properly define AutoMapper config for complex class?
body: <p>I'm working with Entity Framework, and getting ready to redo a project that is currently using EF->BDO->DTO->client with manual conversions for each class along the way.  </p>
  
  <p>I came across AutoMapper and think this would be a better solution overall.  I have had no issues mapping CustomerEF -> CustomerDto, OfficeEF -> OfficeDto, etc, but I am now working on a more complex class, and struggling to get everything in place.  </p>
  
  <p>I feel I am close, and that something has to happen in reverse, but have not been able to identify what I'm missing.</p>
  
  <pre><code>    public class CaseDto
  {
      public int CaseId { get; set; }
      public string CaseReason { get; set; }
      public CustomersDto _customer { get; set; }
      public OfficeDto _office { get; set; }
      public CaseNotesDto[] _caseNotes { get; set; }
  }
  
  public class CustomersDto
  {
      public int CustomerId { get; set; }
      public string CustomerName { get; set; }
  }
  
  public class OfficeDto
  {
      public int OfficeId { get; set; }
      public string OfficeName { get; set; }
  }
  
  public class CaseNotesDto
  {
      public int CaseNotesId { get; set; }
      public int CaseId { get; set; }
      public string CaseNote { get; set; }
  }
  
  // EF objects
  
  public class CaseEF
  {
      public int CaseId { get; set; }
      public string CaseReason { get; set; }
      public int CustomerId { get; set; }
      public int OfficeId { get; set; }
  }
  
  public class CustomerEF
  {
      public int CustomerId { get; set; }
      public string CustomerName { get; set; }
  }
  
  public class OfficeEF
  {
      public int OfficeId { get; set; }
      public string OfficeName { get; set; }
  }
  
  public class CaseNotesEF
  {
      public int CaseNotesId { get; set; }
      public int CaseId { get; set; }
      public string CaseNote { get; set; }
  }
  
  // execution classes
  
  public class CaseFramework
  {
      // set 'ef' variables
      private readonly OfficeEF _officeEf = new OfficeEF { OfficeId = 1, OfficeName = "Washington" };
      private readonly CustomerEF _customerEf = new CustomerEF { CustomerId = 1, CustomerName = "Blips and Chitz" };
  
      private readonly CaseNotesEF[] _caseNotesEf = 
      {
          new CaseNotesEF {CaseNotesId = 1, CaseNote = "Case 1", CaseId = 1000},
          new CaseNotesEF {CaseNotesId = 2, CaseNote = "Case 2", CaseId = 1000}
      };
  
      private readonly CaseEF _case =
          new CaseEF { CaseId = 1000, CaseReason = "Roy is back!", CustomerId = 1, OfficeId = 1 };
  
      public CaseDto GetCase(int caseId)
      {
          Mapper.Initialize(cfg =&gt;
          {
              cfg.CreateMap&lt;OfficeEF, OfficeDto&gt;();
              cfg.CreateMap&lt;CustomerEF, CustomersDto&gt;();
              cfg.CreateMap&lt;CaseNotesEF, CaseNotesDto&gt;();
              cfg.CreateMap&lt;CaseEF, CaseDto&gt;()
                  .ForMember(dest =&gt; dest._customer, opt =&gt; opt.MapFrom(src =&gt; src.CustomerId))
                  .ForMember(dest =&gt; dest._office, opt =&gt; opt.MapFrom(src =&gt; src.OfficeId))
                  .ForMember(dest =&gt; dest._caseNotes,
                      opt =&gt; opt.MapFrom(src =&gt; _caseNotesEf.Where(x =&gt; x.CaseId == caseId)));
          });
  
          Mapper.AssertConfigurationIsValid();
  
          var source = new CaseEF { CaseId = caseId };
          var destination = Mapper.Map&lt;CaseEF, CaseDto&gt;(source);
  
  
          return destination;
      }
  }
  </code></pre>
  
  <p>To run this I am doing:</p>
  
  <pre><code>var b = new CaseFramework();
  var result = b.GetCase(1000);
  </code></pre>
  
  <p>The results are populating the CaseId (set manually) and the CaseNotesDto, but nothing else.</p>
  
  <p>Having the first 3 cfg.CreateMap items in the Mapper.Initialize section makes no difference if they are there or not.</p>
  
  <p>Thanks in advance for any guidance.</p>