Skip to content

Merge | Port SqlBatch support to netfx#3926

Open
edwardneal wants to merge 1 commit intodotnet:mainfrom
edwardneal:public-api/sqlbatch
Open

Merge | Port SqlBatch support to netfx#3926
edwardneal wants to merge 1 commit intodotnet:mainfrom
edwardneal:public-api/sqlbatch

Conversation

@edwardneal
Copy link
Contributor

Description

This is perhaps only tangentially related to merging the netfx and netcore projects, but it merges functionality.

The SQL client driver has had support for server-side batching of SQL statements for a long time, starting with SqlCommandSet. The introduction of the DbBatch abstraction in netcore provided an opportunity to expose this using SqlBatch types in #1825 and #2223.

Although the goal in the original PR was to expose these APIs to both netcore and netfx, at this stage we were still building all of SqlClient using netstandard2.0. This generated various build issues, so the types weren't included.

Since we're now only building the ref assemblies using netstandard2.0, we can port (most of) the SqlBatch surface area to netfx. This harmonises more of the API surface between targets. It also means that in the future, we'll be able to remove the internal SqlCommandSet type, since this duplicates the SqlBatch functionality.

There are now five APIs which were already present present in netcore, but which I haven't ported to netfx. This is because they have a return type of DbBatch* types. Changing them to expose SqlBatch* types will be a breaking change on netcore, and if the method has a different return type in netcore to netfx/netstandard2.0, client applications referencing intermediary netstandard2.0-based libraries won't be able to bind to the method. I don't think this is a problem - the APIs aren't necessary to use SqlBatch functionality.

These APIs are:

  • SqlClientFactory.CanCreateBatch
  • SqlClientFactory.CreateBatch
  • SqlClientFactory.CreateBatchCommand
  • SqlConnection.CanCreateBatch
  • SqlConnection.CreateBatch

Issues

None.

Testing

I've enabled the batching tests on both netcore and netfx. Both pass.

APIs not exposed:
* SqlClientFactory.CanCreateBatch
* SqlClientFactory.CreateBatch
* SqlClientFactory.CreateBatchCommand
* SqlConnection.CanCreateBatch
* SqlConnection.CreateBatch
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ports the SqlBatch API support from .NET Core to .NET Framework, harmonizing the API surface between the two platforms. The SqlBatch feature enables server-side batching of SQL statements, and was previously only available in .NET Core builds.

Changes:

  • Enabled SqlBatch, SqlBatchCommand, and SqlBatchCommandCollection APIs for .NET Framework using conditional compilation
  • Modified test infrastructure to run batch tests on both .NET Framework and .NET Core
  • Removed platform-specific file (SqlBatchCommand.netcore.cs) by consolidating implementations using preprocessor directives

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Batch/BatchTests.cs Added conditional compilation to handle platform differences in API creation (CreateBatch vs new SqlBatch)
src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj Moved batch tests from NET8-only conditional inclusion to unconditional inclusion for all platforms
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlException.cs Made BatchCommand property public for netfx (previously internal), matching netcore behavior
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Scalar.cs Removed #if NET guard from ExecuteScalarBatchAsync to enable it for netfx
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBatchCommandCollection.cs Added conditional compilation to inherit from DbBatchCommandCollection on NET, or just implement IList on netfx
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBatchCommand.netcore.cs Deleted - functionality consolidated into SqlBatchCommand.cs
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBatchCommand.cs Added conditional compilation for properties and methods to support both platforms
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBatch.cs Added conditional compilation to inherit from DbBatch on NET, or implement IDisposable/IAsyncDisposable on netfx
src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.Batch.cs Expanded API surface with conditional compilation to define APIs for both NET and netfx platforms
src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.Batch.NetCoreApp.cs Deleted - definitions moved to main batch reference file
src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj Added references to SqlBatch.cs and SqlBatchCommandCollection.cs
src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj Added reference to Microsoft.Data.SqlClient.Batch.cs
src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj Removed reference to deleted SqlBatchCommand.netcore.cs
src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.csproj Removed conditional item group and reference to deleted Batch.NetCoreApp.cs
src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs Removed duplicate SqlClientFactory batch-related API definitions now in shared file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant