title: Post Action with model class vs DTO
body: <p>This MSDN <a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/part-5" rel="noreferrer">link</a> explains why it is a good practice to use DTOs classes for web API. This is understandable, what confuses me is in the same page, the post method uses the model class instead of the simple DTO one as following:</p>
  
  <pre><code>[ResponseType(typeof(BookDTO))]
  public async Task&lt;IHttpActionResult&gt; PostBook(Book book)
  {
      if (!ModelState.IsValid)
      {
          return BadRequest(ModelState);
      }
  
      db.Books.Add(book);
      await db.SaveChangesAsync();
  
      // New code:
      // Load author name
      db.Entry(book).Reference(x =&gt; x.Author).Load();
  
      var dto = new BookDTO()
      {
          Id = book.Id,
          Title = book.Title,
          AuthorName = book.Author.Name
      };
  
      return CreatedAtRoute("DefaultApi", new { id = book.Id }, dto);
  }
  </code></pre>
  
  <p>I guess my question is: <strong>Should Post/Put action takes model or DTO parameter?</strong></p>
  
  <p><strong>Update</strong>:
  From answers, it looks like using dto is recommended even in case of post/put action, this will lead to another question though, how to map from dto to Model class in case of post action? Let's say we use AutoMapper, I found many links such as <a href="https://lostechies.com/jimmybogard/2009/09/18/the-case-for-two-way-mapping-in-automapper/" rel="noreferrer">this</a> and <a href="https://rogerjohansson.blog/2013/12/01/why-mapping-dtos-to-entities-using-automapper-and-entityframework-is-horrible/" rel="noreferrer">this</a> warn against using it in reverse mapping (i.e. dto => Model class).</p>