1- // Licensed to the .NET Foundation under one or more agreements.
1+ // Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5- #if NET
6-
75using System ;
86using System . Collections . Generic ;
97using System . Data ;
1513namespace Microsoft . Data . SqlClient
1614{
1715 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/SqlBatch/*'/>
18- public class SqlBatch : DbBatch
16+ public class SqlBatch :
17+ #if NET
18+ DbBatch
19+ #else
20+ IDisposable , IAsyncDisposable
21+ #endif
1922 {
2023 private SqlCommand _batchCommand ;
2124 private List < SqlBatchCommand > _commands ;
@@ -33,8 +36,30 @@ public SqlBatch(SqlConnection connection = null, SqlTransaction transaction = nu
3336 Connection = connection ;
3437 Transaction = transaction ;
3538 }
39+
40+ #if NET
41+ /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/DbBatchCommands/*'/>
42+ protected override DbBatchCommandCollection DbBatchCommands => BatchCommands ;
43+
44+ /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/CreateDbBatchCommand/*'/>
45+ protected override DbBatchCommand CreateDbBatchCommand ( ) => new SqlBatchCommand ( ) ;
46+ #endif
47+
48+ #if NETFRAMEWORK
49+ /// <inheritdoc cref="System.IAsyncDisposable.DisposeAsync"/>
50+ public virtual ValueTask DisposeAsync ( )
51+ {
52+ Dispose ( ) ;
53+ return default ;
54+ }
55+ #endif
56+
3657 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Timeout/*'/>
37- public override int Timeout
58+ public
59+ #if NET
60+ override
61+ #endif
62+ int Timeout
3863 {
3964 get
4065 {
@@ -47,12 +72,22 @@ public override int Timeout
4772 _batchCommand . CommandTimeout = value ;
4873 }
4974 }
50- /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/DbBatchCommands/*'/>
51- protected override DbBatchCommandCollection DbBatchCommands => BatchCommands ;
75+
5276 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/BatchCommands/*'/>
53- public new SqlBatchCommandCollection BatchCommands => _providerCommands != null ? _providerCommands : _providerCommands = new SqlBatchCommandCollection ( Commands ) ; // Commands call will check disposed
77+ public
78+ #if NET
79+ new
80+ #endif
81+ SqlBatchCommandCollection BatchCommands => _providerCommands != null ? _providerCommands : _providerCommands = new SqlBatchCommandCollection ( Commands ) ; // Commands call will check disposed
82+
5483 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/DbConnection/*'/>
55- protected override DbConnection DbConnection
84+ protected
85+ #if NET
86+ override
87+ #else
88+ virtual
89+ #endif
90+ DbConnection DbConnection
5691 {
5792 get
5893 {
@@ -65,8 +100,15 @@ protected override DbConnection DbConnection
65100 Connection = ( SqlConnection ) value ;
66101 }
67102 }
103+
68104 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/DbTransaction/*'/>
69- protected override DbTransaction DbTransaction
105+ protected
106+ #if NET
107+ override
108+ #else
109+ virtual
110+ #endif
111+ DbTransaction DbTransaction
70112 {
71113 get
72114 {
@@ -79,60 +121,103 @@ protected override DbTransaction DbTransaction
79121 Transaction = ( SqlTransaction ) value ;
80122 }
81123 }
124+
82125 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Cancel/*'/>
83- public override void Cancel ( )
126+ public
127+ #if NET
128+ override
129+ #endif
130+ void Cancel ( )
84131 {
85132 CheckDisposed ( ) ;
86133 _batchCommand . Cancel ( ) ;
87134 }
135+
88136 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteNonQuery/*'/>
89- public override int ExecuteNonQuery ( )
137+ public
138+ #if NET
139+ override
140+ #endif
141+ int ExecuteNonQuery ( )
90142 {
91143 CheckDisposed ( ) ;
92144 SetupBatchCommandExecute ( ) ;
93145 return _batchCommand . ExecuteNonQuery ( ) ;
94146 }
147+
95148 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteNonQueryAsync/*'/>
96- public override Task < int > ExecuteNonQueryAsync ( CancellationToken cancellationToken = default )
149+ public
150+ #if NET
151+ override
152+ #endif
153+ Task< int > ExecuteNonQueryAsync ( CancellationToken cancellationToken = default )
97154 {
98155 CheckDisposed ( ) ;
99156 SetupBatchCommandExecute ( ) ;
100157 return _batchCommand . ExecuteNonQueryAsync ( cancellationToken ) ;
101158 }
159+
102160 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteScalar/*'/>
103- public override object ExecuteScalar ( )
161+ public
162+ #if NET
163+ override
164+ #endif
165+ object ExecuteScalar ( )
104166 {
105167 CheckDisposed ( ) ;
106168 SetupBatchCommandExecute ( ) ;
107169 return _batchCommand . ExecuteScalar ( ) ;
108170 }
171+
109172 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteScalarAsync/*'/>
110- public override Task < object > ExecuteScalarAsync ( CancellationToken cancellationToken = default )
173+ public
174+ #if NET
175+ override
176+ #endif
177+ Task< object > ExecuteScalarAsync ( CancellationToken cancellationToken = default )
111178 {
112179 CheckDisposed ( ) ;
113180 SetupBatchCommandExecute ( ) ;
114181 return _batchCommand . ExecuteScalarBatchAsync ( cancellationToken ) ;
115182 }
183+
116184 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Prepare/*'/>
117- public override void Prepare ( )
185+ public
186+ #if NET
187+ override
188+ #endif
189+ void Prepare ( )
118190 {
119191 CheckDisposed ( ) ;
120192 }
193+
121194 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/PrepareAsync/*'/>
122- public override Task PrepareAsync ( CancellationToken cancellationToken = default )
195+ public
196+ #if NET
197+ override
198+ #endif
199+ Task PrepareAsync( CancellationToken cancellationToken = default )
123200 {
124201 CheckDisposed ( ) ;
125202 return Task . CompletedTask ;
126203 }
204+
127205 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Dispose/*'/>
128- public override void Dispose ( )
206+ public
207+ #if NET
208+ override
209+ #endif
210+ void Dispose ( )
129211 {
130212 _batchCommand ? . Dispose ( ) ;
131213 _batchCommand = null ;
132214 _commands ? . Clear ( ) ;
133215 _commands = null ;
216+ #if NET
134217 base . Dispose ( ) ;
218+ #endif
135219 }
220+
136221 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Commands/*'/>
137222 public List < SqlBatchCommand > Commands
138223 {
@@ -142,8 +227,13 @@ public List<SqlBatchCommand> Commands
142227 return _commands != null ? _commands : _commands = new List < SqlBatchCommand > ( ) ;
143228 }
144229 }
230+
145231 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Connection/*'/>
146- public new SqlConnection Connection
232+ public
233+ #if NET
234+ new
235+ #endif
236+ SqlConnection Connection
147237 {
148238 get
149239 {
@@ -156,8 +246,13 @@ public List<SqlBatchCommand> Commands
156246 _batchCommand . Connection = value ;
157247 }
158248 }
249+
159250 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Transaction/*'/>
160- public new SqlTransaction Transaction
251+ public
252+ #if NET
253+ new
254+ #endif
255+ SqlTransaction Transaction
161256 {
162257 get
163258 {
@@ -170,24 +265,44 @@ public List<SqlBatchCommand> Commands
170265 _batchCommand . Transaction = value ;
171266 }
172267 }
268+
173269 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteReader/*'/>
174270 public SqlDataReader ExecuteReader ( )
175271 {
176272 CheckDisposed ( ) ;
177273 SetupBatchCommandExecute ( ) ;
178274 return _batchCommand . ExecuteReader ( ) ;
179275 }
276+
180277 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteReaderAsync/*'/>
181- public new Task < SqlDataReader > ExecuteReaderAsync ( CancellationToken cancellationToken = default )
278+ public
279+ #if NET
280+ new
281+ #endif
282+ Task< SqlDataReader > ExecuteReaderAsync ( CancellationToken cancellationToken = default )
182283 {
183284 CheckDisposed ( ) ;
184285 SetupBatchCommandExecute ( ) ;
185286 return _batchCommand . ExecuteReaderAsync ( cancellationToken ) ;
186287 }
288+
187289 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteDbDataReader/*'/>
188- protected override DbDataReader ExecuteDbDataReader ( CommandBehavior behavior ) => ExecuteReader ( ) ;
290+ protected
291+ #if NET
292+ override
293+ #else
294+ virtual
295+ #endif
296+ DbDataReader ExecuteDbDataReader ( CommandBehavior behavior ) => ExecuteReader ( ) ;
297+
189298 /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteDbDataReaderAsync/*'/>
190- protected override Task < DbDataReader > ExecuteDbDataReaderAsync ( CommandBehavior behavior , CancellationToken cancellationToken )
299+ protected
300+ #if NET
301+ override
302+ #else
303+ virtual
304+ #endif
305+ Task < DbDataReader > ExecuteDbDataReaderAsync ( CommandBehavior behavior , CancellationToken cancellationToken )
191306 {
192307 CheckDisposed ( ) ;
193308 SetupBatchCommandExecute ( ) ;
@@ -204,19 +319,16 @@ protected override Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior b
204319 TaskContinuationOptions . ExecuteSynchronously | TaskContinuationOptions . NotOnCanceled ,
205320 TaskScheduler . Default
206321 ) ;
207- }
208- /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/CreateDbBatchCommand/*'/>
209- protected override DbBatchCommand CreateDbBatchCommand ( )
210- {
211- return new SqlBatchCommand ( ) ;
212322 }
323+
213324 private void CheckDisposed ( )
214325 {
215326 if ( _batchCommand is null )
216327 {
217328 throw ADP . ObjectDisposed ( this ) ;
218329 }
219330 }
331+
220332 private void SetupBatchCommandExecute ( )
221333 {
222334 SqlConnection connection = Connection ;
@@ -240,5 +352,3 @@ private void SetupBatchCommandExecute()
240352 }
241353 }
242354}
243-
244- #endif
0 commit comments