Merge | Port SqlBatch support to netfx#3926
Conversation
APIs not exposed: * SqlClientFactory.CanCreateBatch * SqlClientFactory.CreateBatch * SqlClientFactory.CreateBatchCommand * SqlConnection.CanCreateBatch * SqlConnection.CreateBatch
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 |
|
Awesome, I could really use the feature on netfx. It was only the new base types (DbBatch etc) and ref assemblies that stopped it working originally. |
|
This pull request has been marked as stale due to inactivity for more than 30 days. If you would like to keep this pull request open, please provide an update or respond to any comments. Otherwise, it will be closed automatically in 7 days. |
|
This PR is not stale. |
|
@edwardneal - Can you resolve the conflicts here? |
|
Thanks @paulmedynski, I've just merged and resolved the conflicts. |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
mdaigle
left a comment
There was a problem hiding this comment.
LGTM. I will run an API comparison to verify the net core API is unchanged.
|
Verified no changes for net core ✅ |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3926 +/- ##
==========================================
- Coverage 66.63% 64.30% -2.33%
==========================================
Files 279 271 -8
Lines 42999 65743 +22744
==========================================
+ Hits 28651 42278 +13627
- Misses 14348 23465 +9117
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.