From 2fce465d00e3da4238a00c01c7dbece732c7079a Mon Sep 17 00:00:00 2001 From: Mohammad Moattar Date: Sun, 8 Jan 2023 23:44:52 +0000 Subject: [PATCH] Fix the unit of work transactions (#2) --- GitVersion.yml | 2 +- src/LittleBlocks.Ef.UnitOfWork/UnitOfWork.cs | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/GitVersion.yml b/GitVersion.yml index 5cb6811..4889f22 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,4 +1,4 @@ -next-version: 1.0.0 +next-version: 1.0.1 mode: Mainline major-version-bump-message: '\+semver:\s?(breaking|major)' minor-version-bump-message: '\+semver:\s?(feature|minor)' diff --git a/src/LittleBlocks.Ef.UnitOfWork/UnitOfWork.cs b/src/LittleBlocks.Ef.UnitOfWork/UnitOfWork.cs index 62a0aff..e1013e1 100644 --- a/src/LittleBlocks.Ef.UnitOfWork/UnitOfWork.cs +++ b/src/LittleBlocks.Ef.UnitOfWork/UnitOfWork.cs @@ -74,18 +74,16 @@ public async Task SaveChangesAsync(bool ensureAutoHistory = false) public async Task SaveChangesAsync(bool ensureAutoHistory = false, params IUnitOfWork[] unitOfWorks) { - using (var ts = new TransactionScope()) - { - var tasks = unitOfWorks.Select(async unitOfWork => await unitOfWork.SaveChangesAsync(ensureAutoHistory)).ToList(); - var results = await Task.WhenAll(tasks); + using var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); + var tasks = unitOfWorks.Select(async unitOfWork => await unitOfWork.SaveChangesAsync(ensureAutoHistory)).ToList(); + var results = await Task.WhenAll(tasks); - var count = results.Sum(); - count += await SaveChangesAsync(ensureAutoHistory); + var count = results.Sum(); + count += await SaveChangesAsync(ensureAutoHistory); - ts.Complete(); + ts.Complete(); - return count; - } + return count; } public void Dispose()