title: How get Id value from inserted entity in ASP.NET Core Web API post method using AutoMapper
body: <p>My ASP.NET Core Web API has the following <code>Post</code> method to insert a new category entity in database:</p>
  <pre><code>public async Task&lt;ActionResult&gt; Post([FromBody] CategoryDTO categoryDto)
  {
        if (categoryDto == null)
              return BadRequest(&quot;Invalid Data&quot;);
  
         await _categoryService.Add(categoryDto);
  
         return new CreatedAtRouteResult(&quot;GetCategory&quot;, new { id = categoryDto.Id }, categoryDto);
  }
  </code></pre>
  <p>I'm using AutoMapper so I send the DTO from body request, and in <code>CategoryService</code> I get the entity using AutoMapper mappings and create it using my repository (using EF Core <code>SaveChanges</code>):</p>
  <pre><code>public async Task Add(CategoryDTO categoryDto)
  {
       var categoryEntity = _mapper.Map&lt;Category&gt;(categoryDto);
       await _categoryRepository.Create(categoryEntity);
  }
  </code></pre>
  <p>In this way the entity is created but in Post method the id value returned by <code>CreateAdRouteResult</code> is equals zero because it gets the id value from <code>CategoryDto</code>.</p>
  <p>How can I get the id value of the entity inserted?</p>
  <p>Is there any alternative to perform this operation with AutoMapper and get the id value of the created entity?</p>