I found a lot of code working with transaction in an app in which I do a code review.
A lot of times there is no rollback-handling explicit and I first thought, that the rollback will never made and the transaction is therefore never closed.
I found out, after a bit research, that his is wrong and with EF Core a “using” in front of a BeginTransaction causes the transaction to be rollbacked when not commited at the end of the using.
So I found e.g. this:
using var transaction = _dbContext.Database.CurrentTransaction
?? await _dbContext.Database.BeginTransactionAsync(cancellationToken);
Is this all in all good code or bad practice?