diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs
index 0a04d047f8..adb6bb3314 100644
--- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs
+++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs
@@ -477,14 +477,6 @@ internal SqlClientFactory() { }
public override System.Data.Common.DbParameter CreateParameter() { throw null; }
///
public override System.Data.Common.DbDataSourceEnumerator CreateDataSourceEnumerator() { throw null; }
-#if NET
- ///
- public override bool CanCreateBatch { get { throw null; } }
- ///
- public override System.Data.Common.DbBatch CreateBatch() { throw null; }
- ///
- public override System.Data.Common.DbBatchCommand CreateBatchCommand() { throw null; }
-#endif
}
///
public partial class SqlClientLogger
diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.csproj
index a2751a6e57..7e9a20b2ca 100644
--- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.csproj
@@ -27,10 +27,7 @@
-
-
-
diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
index bbbf05277b..3c1ce7853e 100644
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
@@ -665,9 +665,6 @@
Microsoft\Data\SqlClient\SqlBatchCommand.cs
-
- Microsoft\Data\SqlClient\SqlBatchCommand.netcore.cs
-
Microsoft\Data\SqlClient\SqlBatchCommandCollection.cs
diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj
index 2735cce404..1759a61180 100644
--- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj
@@ -20,6 +20,7 @@
+
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
index 51e301a835..2109453adb 100644
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
@@ -657,9 +657,15 @@
Microsoft\Data\SqlClient\SqlAuthenticationToken.cs
+
+ Microsoft\Data\SqlClient\SqlBatch.cs
+
Microsoft\Data\SqlClient\SqlBatchCommand.cs
+
+ Microsoft\Data\SqlClient\SqlBatchCommandCollection.cs
+
Microsoft\Data\SqlClient\SqlBuffer.cs
diff --git a/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.Batch.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.Batch.NetCoreApp.cs
deleted file mode 100644
index a693a7f9c1..0000000000
--- a/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.Batch.NetCoreApp.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Data.SqlClient
-{
- ///
- public partial class SqlBatchCommand
- {
- ///
- public Microsoft.Data.SqlClient.SqlCommandColumnEncryptionSetting ColumnEncryptionSetting { get { throw null; } set { } }
- }
-
- ///
- public partial class SqlConnection
- {
- ///
- public override bool CanCreateBatch { get { throw null; } }
- ///
- protected override System.Data.Common.DbBatch CreateDbBatch() => throw null;
- }
-
- ///
- public partial class SqlException
- {
- ///
- protected override System.Data.Common.DbBatchCommand DbBatchCommand => throw null;
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.Batch.cs b/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.Batch.cs
index 411c88a7f2..48961940d7 100644
--- a/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.Batch.cs
+++ b/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.Batch.cs
@@ -5,31 +5,31 @@
namespace Microsoft.Data.SqlClient
{
///
- public class SqlBatch : System.Data.Common.DbBatch
+ public class SqlBatch :
+ #if NET
+ System.Data.Common.DbBatch
+ #else
+ System.IDisposable, System.IAsyncDisposable
+ #endif
{
- ///
- public SqlBatch() { throw null; }
- ///
- public SqlBatch(Microsoft.Data.SqlClient.SqlConnection connection, Microsoft.Data.SqlClient.SqlTransaction transaction = null) { throw null; }
+ #if NET
///
- public override int Timeout { get => throw null; set { } }
- ///
- public System.Collections.Generic.List Commands { get { throw null; } }
+ public override int Timeout { get => throw null; set { } }
///
public new Microsoft.Data.SqlClient.SqlConnection Connection { get => throw null; set { } }
///
public new Microsoft.Data.SqlClient.SqlTransaction Transaction { get => throw null; set { } }
///
- public new SqlBatchCommandCollection BatchCommands { get => throw null; }
+ public new Microsoft.Data.SqlClient.SqlBatchCommandCollection BatchCommands { get => throw null; }
///
protected override System.Data.Common.DbBatchCommandCollection DbBatchCommands { get => throw null; }
///
protected override System.Data.Common.DbConnection DbConnection { get => throw null; set { } }
///
- protected override System.Data.Common.DbTransaction DbTransaction { get => throw null; set { } }
+ protected override System.Data.Common.DbTransaction DbTransaction { get => throw null; set { } }
///
public override void Cancel() => throw null;
- ///
+ ///
protected override System.Data.Common.DbBatchCommand CreateDbBatchCommand() => throw null;
///
public override void Dispose() => throw null;
@@ -41,8 +41,6 @@ public class SqlBatch : System.Data.Common.DbBatch
public override int ExecuteNonQuery() => throw null;
///
public override System.Threading.Tasks.Task ExecuteNonQueryAsync(System.Threading.CancellationToken cancellationToken = default) => throw null;
- ///
- public Microsoft.Data.SqlClient.SqlDataReader ExecuteReader() => throw null;
///
public new System.Threading.Tasks.Task ExecuteReaderAsync(System.Threading.CancellationToken cancellationToken = default) => throw null;
///
@@ -53,79 +51,195 @@ public class SqlBatch : System.Data.Common.DbBatch
public override void Prepare() => throw null;
///
public override System.Threading.Tasks.Task PrepareAsync(System.Threading.CancellationToken cancellationToken = default) => throw null;
+#else
+ ///
+ public int Timeout { get => throw null; set { } }
+ ///
+ public Microsoft.Data.SqlClient.SqlConnection Connection { get => throw null; set { } }
+ ///
+ public Microsoft.Data.SqlClient.SqlTransaction Transaction { get => throw null; set { } }
+ ///
+ public Microsoft.Data.SqlClient.SqlBatchCommandCollection BatchCommands { get => throw null; }
+ ///
+ protected virtual System.Data.Common.DbConnection DbConnection { get => throw null; set { } }
+ ///
+ protected virtual System.Data.Common.DbTransaction DbTransaction { get => throw null; set { } }
+ ///
+ public void Cancel() => throw null;
+ ///
+ public void Dispose() => throw null;
+ ///
+ protected virtual System.Data.Common.DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior) => throw null;
+ ///
+ protected virtual System.Threading.Tasks.Task ExecuteDbDataReaderAsync(System.Data.CommandBehavior behavior, System.Threading.CancellationToken cancellationToken) => throw null;
+ ///
+ public int ExecuteNonQuery() => throw null;
+ ///
+ public System.Threading.Tasks.Task ExecuteNonQueryAsync(System.Threading.CancellationToken cancellationToken = default) => throw null;
+ ///
+ public System.Threading.Tasks.Task ExecuteReaderAsync(System.Threading.CancellationToken cancellationToken = default) => throw null;
+ ///
+ public object ExecuteScalar() => throw null;
+ ///
+ public System.Threading.Tasks.Task
-
-
-
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Batch/BatchTests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Batch/BatchTests.cs
index a883eb9b88..5322e86093 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Batch/BatchTests.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Batch/BatchTests.cs
@@ -50,8 +50,12 @@ public static void ConnectionCanCreateBatch()
{
using (var connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
+ #if NET
Assert.True(connection.CanCreateBatch);
using (var batch = connection.CreateBatch())
+ #else
+ using (var batch = new SqlBatch(connection))
+ #endif
{
Assert.NotNull(batch);
Assert.Equal(connection, batch.Connection);
@@ -63,13 +67,16 @@ public static void ConnectionCanCreateBatch()
}
}
-#if NET8_0_OR_GREATER
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
public static void SqlBatchCanCreateParameter()
{
using var connection = new SqlConnection(DataTestUtility.TCPConnectionString);
connection.Open();
+#if NET
using DbBatch batch = connection.CreateBatch();
+#else
+ using SqlBatch batch = new SqlBatch(connection);
+#endif
SqlBatchCommand batchCommand = new SqlBatchCommand("SELECT @p");
Assert.True(batchCommand.CanCreateParameter);
@@ -81,7 +88,6 @@ public static void SqlBatchCanCreateParameter()
batch.BatchCommands.Add(batchCommand);
batch.ExecuteNonQuery();
}
-#endif
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
public static void StoredProcedureBatchSupported()
@@ -154,7 +160,11 @@ public static void ProviderApi()
int resultCount = 0;
int rowCount = 0;
var dbProviderFactory = SqlClientFactory.Instance;
+ #if NET
DbBatch batch = dbProviderFactory.CreateBatch();
+ #else
+ SqlBatch batch = new SqlBatch();
+ #endif
using (var connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
connection.Open();
@@ -167,7 +177,11 @@ public static void ProviderApi()
p2.ParameterName = "@p2";
p1.Value = 50.0f;
p2.Value = 10248;
+ #if NET
DbBatchCommand command = dbProviderFactory.CreateBatchCommand();
+ #else
+ SqlBatchCommand command = new SqlBatchCommand();
+ #endif
command.CommandText = "UPDATE Orders SET Freight=@p1 WHERE OrderID=@p2";
command.Parameters.Add(p1);
command.Parameters.Add(p2);
@@ -178,7 +192,11 @@ public static void ProviderApi()
DbParameter parameter = dbProviderFactory.CreateParameter();
parameter.ParameterName = "@p4";
parameter.Value = 10248;
+ #if NET
DbBatchCommand command = dbProviderFactory.CreateBatchCommand();
+ #else
+ SqlBatchCommand command = new SqlBatchCommand();
+ #endif
command.CommandText = $"SELECT Freight FROM Orders WHERE OrderID={parameter.ParameterName}";
command.Parameters.Add(parameter);
batch.BatchCommands.Add(command);