@@ -12,21 +12,21 @@ public sealed class MySqlTransaction : DbTransaction
12
12
public override void Commit ( ) =>
13
13
CommitAsync ( IOBehavior . Synchronous , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
14
14
15
- public Task CommitAsync ( CancellationToken cancellationToken = default ( CancellationToken ) ) =>
16
- CommitAsync ( m_connection . AsyncIOBehavior , cancellationToken ) ;
15
+ public Task CommitAsync ( CancellationToken cancellationToken = default ) =>
16
+ CommitAsync ( m_connection ? . AsyncIOBehavior ?? IOBehavior . Asynchronous , cancellationToken ) ;
17
17
18
18
internal async Task CommitAsync ( IOBehavior ioBehavior , CancellationToken cancellationToken )
19
19
{
20
20
VerifyNotDisposed ( ) ;
21
- if ( m_isFinished )
21
+ if ( m_connection == null )
22
22
throw new InvalidOperationException ( "Already committed or rolled back." ) ;
23
23
24
24
if ( m_connection . CurrentTransaction == this )
25
25
{
26
26
using ( var cmd = new MySqlCommand ( "commit" , m_connection , this ) )
27
27
await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
28
28
m_connection . CurrentTransaction = null ;
29
- m_isFinished = true ;
29
+ m_connection = null ;
30
30
}
31
31
else if ( m_connection . CurrentTransaction != null )
32
32
{
@@ -41,21 +41,21 @@ internal async Task CommitAsync(IOBehavior ioBehavior, CancellationToken cancell
41
41
public override void Rollback ( ) =>
42
42
RollbackAsync ( IOBehavior . Synchronous , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
43
43
44
- public Task RollbackAsync ( CancellationToken cancellationToken = default ( CancellationToken ) ) =>
45
- RollbackAsync ( m_connection . AsyncIOBehavior , cancellationToken ) ;
44
+ public Task RollbackAsync ( CancellationToken cancellationToken = default ) =>
45
+ RollbackAsync ( m_connection ? . AsyncIOBehavior ?? IOBehavior . Asynchronous , cancellationToken ) ;
46
46
47
47
internal async Task RollbackAsync ( IOBehavior ioBehavior , CancellationToken cancellationToken )
48
48
{
49
49
VerifyNotDisposed ( ) ;
50
- if ( m_isFinished )
50
+ if ( m_connection == null )
51
51
throw new InvalidOperationException ( "Already committed or rolled back." ) ;
52
52
53
53
if ( m_connection . CurrentTransaction == this )
54
54
{
55
55
using ( var cmd = new MySqlCommand ( "rollback" , m_connection , this ) )
56
56
await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
57
57
m_connection . CurrentTransaction = null ;
58
- m_isFinished = true ;
58
+ m_connection = null ;
59
59
}
60
60
else if ( m_connection . CurrentTransaction != null )
61
61
{
@@ -77,7 +77,8 @@ protected override void Dispose(bool disposing)
77
77
{
78
78
if ( disposing )
79
79
{
80
- if ( ! m_isFinished && m_connection ? . CurrentTransaction == this )
80
+ m_isDisposed = true ;
81
+ if ( m_connection ? . CurrentTransaction == this )
81
82
{
82
83
if ( m_connection . Session . IsConnected )
83
84
{
@@ -103,11 +104,11 @@ internal MySqlTransaction(MySqlConnection connection, IsolationLevel isolationLe
103
104
104
105
private void VerifyNotDisposed ( )
105
106
{
106
- if ( m_connection == null )
107
+ if ( m_isDisposed )
107
108
throw new ObjectDisposedException ( nameof ( MySqlTransaction ) ) ;
108
109
}
109
110
110
111
MySqlConnection m_connection ;
111
- bool m_isFinished ;
112
+ bool m_isDisposed ;
112
113
}
113
114
}
0 commit comments