IDbContextTransaction not working rollback

Viewed 11

I have a windows application with .net framework 4.6 and the repository using .net framework core 3.1. I can get the transaction correctly, but it seems that it is not saving the changes in the transaction and when it falls into the catch error, it goes through the Rollback but does not perform any reversal of the saved record. My code basically saves a new order and then I simulate the error to validate the rollback and not save the order.

private async Task ManageNFeConsultaLote(EventoNFe eventoNFe, retConsReciNFe retorno)
{
    _transactionRepository = (ITransactionRepository)_serviceProvider.GetService(typeof(ITransactionRepository));
    using (var transaction = _transactionRepository.GetTransaction())
    {
        try
        {
            _faturamentoService.CreateOrder();
            transaction.Commit();
        }
        catch (Exception e)
        {
            transaction.Rollback();
            throw e;
        }
    }
}

This works fine in the API application, but in the windows application it is not doing rollback. should i use a different approach because etar in .net framework 4.6 and context uses .net framework core 3.1?

0 Answers
Related