title: AutoMapper: Mapping between DTO and Entity
body: <p>I am working with a ASP.NET Core WebAPI and I want to do CRUD for my objects called &quot;Item&quot;.
  I am using EF Core to work with a SQL Database and I have two models that represents my objects.</p>
  <ol>
  <li><strong>ItemDto</strong> - Data Transfer Object for an Item</li>
  <li><strong>ItemEntity</strong> - Database Object (represents a row in a table 1:1)</li>
  </ol>
  <p>My HTTP GET one and HTTP GET many methods works in such way that it</p>
  <ol>
  <li><p>Get ItemRepository instance</p>
  </li>
  <li><p>Fetch one or more <strong>ItemEntity</strong></p>
  </li>
  <li><p>Map it to <strong>ItemDto</strong> by using AutoMapper
  This is initalized in my constructor such as</p>
  <pre><code>m_itemDtoMapper = new Mapper(new MapperConfiguration(cfg =&gt; cfg.CreateMap&lt;ItemEntity, ItemDto&gt;()));
  </code></pre>
  </li>
  </ol>
  <p>And in my WebAPI method I map it to a ItemDto with the following line (for the GET many case):</p>
  <pre><code>var itemDtos = m_itemDtoMapper.Map&lt;IEnumerable&lt;ItemEntity&gt;, ICollection&lt;ItemDto&gt;&gt;(items);
  </code></pre>
  <p>This works well and the AutoMapper is very powerful. The questions I have now is:</p>
  <ol>
  <li>Is this the standard way of managing the relationship between database entities and data transfer objects?</li>
  <li>In the CreateItem method, I need to do reverse mapping. Instead of mapping ItemEntity to ItemDto, I need to map a ItemDto to an ItemEntity. How shall I do this? Creating a copy of my mapper just with switched entities works but is that how its supposed to be done? i.e two mappers.</li>
  </ol>