Savechanges() method returns the added record id

Asked

Viewed 51 times

0

I have in my Repositorygenerico the methods :

public virtual async Task Adicionar(TEntity entity)
{
    DbSet.Add(entity);
    await SaveChanges();
}

public async Task<int> SaveChanges()
{
    return await Db.SaveChangesAsync();
}

The Savechanges method makes the recorded ID return, as I could catch this return?

Example in controller:

[Route("Fornecedores/criar-novo-fornecedor")]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(FornecedorViewModel fornecedorViewModel)
{

     var dados = _mapper.Map<Fornecedor>(fornecedorViewModel);
     await _fornecedorRepository.Adicionar(dados);

}

1 answer

-2

  • 1

    Ok... I edit the above answer or create a new one ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.