Merge | Port SqlBatch support to netfx#3926
Open
edwardneal wants to merge 1 commit intodotnet:mainfrom
Open
Conversation
APIs not exposed: * SqlClientFactory.CanCreateBatch * SqlClientFactory.CreateBatch * SqlClientFactory.CreateBatchCommand * SqlConnection.CanCreateBatch * SqlConnection.CreateBatch
Contributor
There was a problem hiding this comment.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Issues
None.
Testing
I've enabled the batching tests on both netcore and netfx. Both pass.