Skip to content

Commit

Permalink
Fix the unit of work transactions (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
moattarwork authored Jan 8, 2023
1 parent f85601a commit 2fce465
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -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)'
Expand Down
16 changes: 7 additions & 9 deletions src/LittleBlocks.Ef.UnitOfWork/UnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,16 @@ public async Task<int> SaveChangesAsync(bool ensureAutoHistory = false)

public async Task<int> 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()
Expand Down

0 comments on commit 2fce465

Please sign in to comment.