@@ -18,6 +18,7 @@ internal class Connection : SqlConnection
18
18
{
19
19
private NpgsqlConnection underlyingConnection ;
20
20
private NpgsqlTransaction activeTransaction ;
21
+ private bool activeTransactionIsCompleted ;
21
22
22
23
/// <inheritdoc/>
23
24
public override DbConnection UnderlyingConnection => underlyingConnection ;
@@ -36,6 +37,7 @@ public override void BeginTransaction()
36
37
EnsureIsNotDisposed ( ) ;
37
38
EnsureTransactionIsNotActive ( ) ;
38
39
activeTransaction = underlyingConnection . BeginTransaction ( ) ;
40
+ activeTransactionIsCompleted = false ;
39
41
}
40
42
41
43
/// <inheritdoc/>
@@ -45,6 +47,7 @@ public override void BeginTransaction(IsolationLevel isolationLevel)
45
47
EnsureIsNotDisposed ( ) ;
46
48
EnsureTransactionIsNotActive ( ) ;
47
49
activeTransaction = underlyingConnection . BeginTransaction ( SqlHelper . ReduceIsolationLevel ( isolationLevel ) ) ;
50
+ activeTransactionIsCompleted = false ;
48
51
}
49
52
50
53
public override void Commit ( bool rollbackOnFail = false )
@@ -56,6 +59,7 @@ public override void Commit(bool rollbackOnFail = false)
56
59
if ( ! IsTransactionCompleted ( ) ) {
57
60
ActiveTransaction . Commit ( ) ;
58
61
}
62
+ activeTransactionIsCompleted = true ;
59
63
}
60
64
catch when ( rollbackOnFail ) {
61
65
ActiveTransaction . Rollback ( ) ;
@@ -75,6 +79,7 @@ public override async Task CommitAsync(bool rollbackOnFail = false, Cancellation
75
79
if ( ! IsTransactionCompleted ( ) ) {
76
80
await ActiveTransaction . CommitAsync ( token ) . ConfigureAwait ( false ) ;
77
81
}
82
+ activeTransactionIsCompleted = true ;
78
83
}
79
84
catch when ( rollbackOnFail ) {
80
85
await ActiveTransaction . RollbackAsync ( token ) . ConfigureAwaitFalse ( ) ; ;
@@ -194,7 +199,7 @@ private async Task ExecuteNonQueryAsync(string commandText, CancellationToken to
194
199
195
200
private bool IsTransactionCompleted ( )
196
201
{
197
- return activeTransaction != null && activeTransaction . IsCompleted ;
202
+ return activeTransaction != null && activeTransactionIsCompleted ;
198
203
}
199
204
200
205
// Constructors
@@ -206,4 +211,4 @@ public Connection(SqlDriver driver)
206
211
underlyingConnection = new NpgsqlConnection ( ) ;
207
212
}
208
213
}
209
- }
214
+ }
0 commit comments