Skip to content

Merge | Port SqlBatch support to netfx#3926

Merged
mdaigle merged 5 commits intodotnet:mainfrom
edwardneal:public-api/sqlbatch
Apr 21, 2026
Merged

Merge | Port SqlBatch support to netfx#3926
mdaigle merged 5 commits intodotnet:mainfrom
edwardneal:public-api/sqlbatch

Conversation

@edwardneal
Copy link
Copy Markdown
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
Copy Markdown
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

@Wraith2
Copy link
Copy Markdown
Contributor

Wraith2 commented Feb 18, 2026

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.

@paulmedynski paulmedynski modified the milestones: 7.0.1, 7.1.0-preview1 Mar 9, 2026
@github-actions
Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Apr 11, 2026
@edwardneal
Copy link
Copy Markdown
Contributor Author

This PR is not stale.

@github-actions github-actions Bot removed the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Apr 12, 2026
@paulmedynski
Copy link
Copy Markdown
Contributor

@edwardneal - Can you resolve the conflicts here?

@paulmedynski paulmedynski self-assigned this Apr 14, 2026
@edwardneal
Copy link
Copy Markdown
Contributor Author

Thanks @paulmedynski, I've just merged and resolved the conflicts.

@paulmedynski
Copy link
Copy Markdown
Contributor

/azp run

@paulmedynski paulmedynski moved this from Backlog to In review in SqlClient Board Apr 16, 2026
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

Comment thread src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.cs
Comment thread src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBatch.cs Outdated
mdaigle
mdaigle previously approved these changes Apr 16, 2026
Copy link
Copy Markdown
Contributor

@mdaigle mdaigle left a comment

Choose a reason for hiding this comment

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

LGTM. I will run an API comparison to verify the net core API is unchanged.

@mdaigle
Copy link
Copy Markdown
Contributor

mdaigle commented Apr 16, 2026

Verified no changes for net core ✅

@mdaigle
Copy link
Copy Markdown
Contributor

mdaigle commented Apr 20, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@paulmedynski paulmedynski added Public API 🆕 Issues/PRs that introduce new APIs to the driver. Hotfix Candidate 🚑 Issues/PRs that are candidate for backporting to earlier supported versions. labels Apr 21, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.30%. Comparing base (f5c41ee) to head (7e416bd).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
...rosoft/Data/SqlClient/SqlBatchCommandCollection.cs 13.33% 13 Missing ⚠️
...SqlClient/src/Microsoft/Data/SqlClient/SqlBatch.cs 75.00% 1 Missing ⚠️
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     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 64.30% <33.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paulmedynski paulmedynski removed the Hotfix Candidate 🚑 Issues/PRs that are candidate for backporting to earlier supported versions. label Apr 21, 2026
@mdaigle mdaigle merged commit 3ae3274 into dotnet:main Apr 21, 2026
303 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board Apr 21, 2026
@edwardneal edwardneal deleted the public-api/sqlbatch branch April 21, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Public API 🆕 Issues/PRs that introduce new APIs to the driver.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants