Skip to content

Commit bf7bfdd

Browse files
authored
Merge pull request #4 from paulvanbladel/master
fix: DbContextTransactionFilter needs explicit check on exception inner action
2 parents 482d780 + 0e121e0 commit bf7bfdd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ContosoUniversity/Infrastructure/DbContextTransactionFilter.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
2020
{
2121
await _dbContext.BeginTransactionAsync();
2222

23-
await next();
23+
var actionExecuted = await next();
24+
if (actionExecuted.Exception != null && !actionExecuted.ExceptionHandled)
25+
{
26+
_dbContext.RollbackTransaction();
2427

25-
await _dbContext.CommitTransactionAsync();
28+
}
29+
else
30+
{
31+
await _dbContext.CommitTransactionAsync();
32+
33+
}
2634
}
2735
catch (Exception)
2836
{

0 commit comments

Comments
 (0)