Browse Source

Rollback non-relational database transactions.

Also, added comment to clarify it.
pull/7530/head
Halil İbrahim Kalkan 6 years ago
parent
commit
bfb896dc3f
  1. 16
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/EfCoreTransactionApi.cs
  2. 10
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs

16
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/EfCoreTransactionApi.cs

@ -48,11 +48,19 @@ namespace Volo.Abp.Uow.EntityFrameworkCore
DbContextTransaction.Dispose(); DbContextTransaction.Dispose();
} }
public Task RollbackAsync(CancellationToken cancellationToken) public async Task RollbackAsync(CancellationToken cancellationToken)
{ {
return DbContextTransaction.RollbackAsync( await DbContextTransaction.RollbackAsync(CancellationTokenProvider.FallbackToProvider(cancellationToken));
CancellationTokenProvider.FallbackToProvider(cancellationToken)
); foreach (var dbContext in AttendedDbContexts)
{
if (dbContext.As<DbContext>().HasRelationalTransactionManager())
{
continue; //Relational databases use the shared transaction
}
await dbContext.Database.RollbackTransactionAsync(CancellationTokenProvider.Token);
}
} }
} }
} }

10
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs

@ -191,7 +191,10 @@ namespace Volo.Abp.Uow.EntityFrameworkCore
} }
else else
{ {
dbContext.Database.BeginTransaction(); //TODO: Why not using the new created transaction? /* No need to store the returning IDbContextTransaction for non-relational databases
* since EfCoreTransactionApi will handle the commit/rollback over the DbContext instance.
*/
dbContext.Database.BeginTransaction();
} }
activeTransaction.AttendedDbContexts.Add(dbContext); activeTransaction.AttendedDbContexts.Add(dbContext);
@ -236,7 +239,10 @@ namespace Volo.Abp.Uow.EntityFrameworkCore
} }
else else
{ {
await dbContext.Database.BeginTransactionAsync(GetCancellationToken()); //TODO: Why not using the new created transaction? /* No need to store the returning IDbContextTransaction for non-relational databases
* since EfCoreTransactionApi will handle the commit/rollback over the DbContext instance.
*/
await dbContext.Database.BeginTransactionAsync(GetCancellationToken());
} }
activeTransaction.AttendedDbContexts.Add(dbContext); activeTransaction.AttendedDbContexts.Add(dbContext);

Loading…
Cancel
Save