title: AutoMapper mapping ICollection with EF
body: <p>I'm trying to map nested ICollection of one of my models to existing Dto, but I'm struggling to Map it properly with AutoMapper</p>
  
  <p><strong>Models:</strong></p>
  
  <pre><code>public class Ingredient : BaseEntity&lt;long&gt;
  {
      [MaxLength(100)]
      public string Name { get; set; }
      [ForeignKey("Id")]
      public int CustomerId { get; set; }
      public bool IsPackaging { get; set; }
      public virtual ICollection&lt;ProductIngredient&gt; ProductIngredient { get; set; }
      public virtual ICollection&lt;IngredientComposition&gt; IngredientComposition { get; set; }
  }
  </code></pre>
  
  <p><strong>Collection Model:</strong> </p>
  
  <pre><code>public class IngredientComposition : BaseEntity&lt;int&gt;
  {
      [MaxLength(20)]
      public string Type { get; set; }
      [MaxLength(200)]
      public string Key { get; set; }
      [MaxLength(200)]
      public string Value { get; set; }
  }
  </code></pre>
  
  <p><strong>Dto:</strong></p>
  
  <pre><code>public class IngredientDto
  {
      public long Id { get; set; }
      public DateTime CretedOn { get; set; }
      public DateTime UpdatedOn { get; set; }
      public string Name { get; set; }
      public int CustomerId { get; set; }
      public int UsedCount { get; set; }
      public bool IsPackaging { get; set; }
      public IList&lt;Composition&gt; Ingredients { get; set; }
  }
  
  public class Composition
  {
      public string Type { get; set; }
      public string Key { get; set; }
      public string Value { get; set; }
  }
  </code></pre>
  
  <p>My maps looks as follows as I'm struggling to properly set "ForMemeber" method(s):</p>
  
  <pre><code>CreateMap&lt;Ingredient, IngredientDto&gt;();
  CreateMap&lt;IngredientDto, Ingredient&gt;();
  </code></pre>
  
  <p>Any help much appropriated!
  Thanks</p>
  
  <p>EDIT:</p>
  
  <p>This is how I'm getting data:</p>
  
  <pre><code>return await _context.Ingredients
                       .Where(i =&gt; i.CustomerId ==_userResolverService.GetCustomerId())
                       .Include(i =&gt; i.IngredientComposition)
                       .Select(i =&gt; _mapper.Map&lt;Ingredient, IngredientDto&gt;(i))
                       .OrderBy(i =&gt; i.Name)
                       .ToListAsync();
  </code></pre>