title: In which layer to map from entity to DTO in my projects architecture
body: <p>I know there are thousands articles about it and I read many of them but I am still not sure what to do it my specific case.</p>
  <p>I am writing a .NET Core 5 application and have 3 project layers:</p>
  <ol>
  <li>API - REST, interacts with the client-side code, gets &amp; returns DTOs.</li>
  <li>BLL - Business logic - most code is here.</li>
  <li>DAL - Repository pattern =&gt; Calls the SQL Server database. Works with entities.</li>
  </ol>
  <p>I am using entities in my DAL layer and map them later to DTO models which are returned in the API to the API caller.</p>
  <p>If I write in Google <em>&quot;In which layer to map from entity to DTO?&quot;</em> I get the answer:</p>
  <blockquote>
  <p>In that case, the service layer maps domain entities to data contracts (DTO's).</p>
  </blockquote>
  <p><strong>The problem</strong> is that I don't have a service layer and I don't want to create it.</p>
  <p><strong>The question</strong> is, in which layer in my layers structure should I do the mapping from entity to DTO?</p>
  <p>In my structure I guess I can do it in 2 places (I am not sure which one is better and why):</p>
  <ol>
  <li><p>In the BLL - instead of returning an entity, I can map it to a DTO (using an <code>AutoMapper</code>) and return the DTO to the API layer.</p>
  </li>
  <li><p>In the API - Receiving an Entity from the BLL and then mapping it to a DTO (using an <code>AutoMapper</code> or <code>ResultFilter</code>) and returning it to the API caller.</p>
  </li>
  </ol>