1
- using System ;
1
+ using System ;
2
2
using System . Data ;
3
3
using System . Data . Common ;
4
4
using System . Threading ;
@@ -34,8 +34,8 @@ public MySqlCommand(string commandText, MySqlConnection connection, MySqlTransac
34
34
{
35
35
CommandId = Interlocked . Increment ( ref s_commandId ) ;
36
36
CommandText = commandText ;
37
- DbConnection = connection ;
38
- DbTransaction = transaction ;
37
+ Connection = connection ;
38
+ Transaction = transaction ;
39
39
m_parameterCollection = new MySqlParameterCollection ( ) ;
40
40
CommandType = CommandType . Text ;
41
41
}
@@ -49,6 +49,8 @@ public MySqlCommand(string commandText, MySqlConnection connection, MySqlTransac
49
49
}
50
50
}
51
51
52
+ public new MySqlParameter CreateParameter ( ) => ( MySqlParameter ) base . CreateParameter ( ) ;
53
+
52
54
public override void Cancel ( ) => Connection . Cancel ( this ) ;
53
55
54
56
public override int ExecuteNonQuery ( ) =>
@@ -57,6 +59,10 @@ public override int ExecuteNonQuery() =>
57
59
public override object ExecuteScalar ( ) =>
58
60
ExecuteScalarAsync ( IOBehavior . Synchronous , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
59
61
62
+ public new MySqlDataReader ExecuteReader ( ) => ( MySqlDataReader ) base . ExecuteReader ( ) ;
63
+
64
+ public new MySqlDataReader ExecuteReader ( CommandBehavior commandBehavior ) => ( MySqlDataReader ) base . ExecuteReader ( commandBehavior ) ;
65
+
60
66
public override void Prepare ( )
61
67
{
62
68
// NOTE: Prepared statements in MySQL are not currently supported.
@@ -67,6 +73,8 @@ public override void Prepare()
67
73
68
74
public override string CommandText { get ; set ; }
69
75
public override int CommandTimeout { get ; set ; }
76
+ public new MySqlConnection Connection { get ; set ; }
77
+ public new MySqlTransaction Transaction { get ; set ; }
70
78
71
79
public override CommandType CommandType
72
80
{
@@ -99,9 +107,19 @@ public override UpdateRowSource UpdatedRowSource
99
107
100
108
public long LastInsertedId { get ; internal set ; }
101
109
102
- protected override DbConnection DbConnection { get ; set ; }
110
+ protected override DbConnection DbConnection
111
+ {
112
+ get => Connection ;
113
+ set => Connection = ( MySqlConnection ) value ;
114
+ }
115
+
103
116
protected override DbParameterCollection DbParameterCollection => m_parameterCollection ;
104
- protected override DbTransaction DbTransaction { get ; set ; }
117
+
118
+ protected override DbTransaction DbTransaction
119
+ {
120
+ get => Transaction ;
121
+ set => Transaction = ( MySqlTransaction ) value ;
122
+ }
105
123
106
124
protected override DbParameter CreateDbParameter ( )
107
125
{
@@ -148,8 +166,6 @@ protected override void Dispose(bool disposing)
148
166
}
149
167
}
150
168
151
- internal new MySqlConnection Connection => ( MySqlConnection ) DbConnection ;
152
-
153
169
/// <summary>
154
170
/// Registers <see cref="Cancel"/> as a callback with <paramref name="token"/> if cancellation is supported.
155
171
/// </summary>
@@ -180,11 +196,11 @@ private bool IsValid(out Exception exception)
180
196
exception = null ;
181
197
if ( m_parameterCollection == null )
182
198
exception = new ObjectDisposedException ( GetType ( ) . Name ) ;
183
- else if ( DbConnection == null )
199
+ else if ( Connection == null )
184
200
exception = new InvalidOperationException ( "Connection property must be non-null." ) ;
185
- else if ( DbConnection . State != ConnectionState . Open && DbConnection . State != ConnectionState . Connecting )
186
- exception = new InvalidOperationException ( "Connection must be Open; current state is {0}" . FormatInvariant ( DbConnection . State ) ) ;
187
- else if ( DbTransaction != Connection . CurrentTransaction )
201
+ else if ( Connection . State != ConnectionState . Open && Connection . State != ConnectionState . Connecting )
202
+ exception = new InvalidOperationException ( "Connection must be Open; current state is {0}" . FormatInvariant ( Connection . State ) ) ;
203
+ else if ( Transaction != Connection . CurrentTransaction )
188
204
exception = new InvalidOperationException ( "The transaction associated with this command is not the connection's active transaction." ) ;
189
205
else if ( string . IsNullOrWhiteSpace ( CommandText ) )
190
206
exception = new InvalidOperationException ( "CommandText must be specified" ) ;
0 commit comments