Repository navigation
Command and transaction tidy: one reader core per file, one connection restore - #282
Merged
Merged
Conversation
…ction restore
The four DbCommand reader overloads (handler and transform, plain and
ValueTask) each opened the connection and disposed the reader with the same
four-line block, and the SqlCommand overloads did the same. Each file now has
two private cores, one returning ValueTask and one ValueTask<T>, that own the
open and the disposal. An overload passes its handler as the argument together
with a static lambda that calls it, so there is no closure and the per-call
allocation is unchanged. The null checks moved into the cores, which are async,
so a null argument is still reported through the returned task.
The SQL Server package's transaction code no longer carries its own copy of the
restore pair. It takes a DbConnection, so the core package's helper serves
both.
Fix: CreateCommand, CreateTextCommand and CreateStoredProcedureCommand on a
SqlTransaction that has no connection threw ArgumentNullException named
"connection". They now throw InvalidOperationException("Transaction has no
connection."), as the core package does. A test and a release note cover it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the explicit private on the two cores, as the rest of the code does, and wrap their comment to the soft line limit. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
Two small refinements from the rc.17 pass, and one fix they turned up.
DbCommandreader overloads (handler and transform, plain andValueTask) each carried the same open-and-dispose block, behind#if NETSTANDARD2_0; theSqlCommandoverloads did the same behind#if NET472. Each file now has two private cores, one returningValueTaskand oneValueTask<T>, that own the open and the reader's disposal. An overload passes its handler as the argument together with a static lambda that calls it: no closure, so no new allocation. The null checks moved into the cores, which are async, so a null argument is still reported through the returned task, with the same parameter name.DbConnection, so Core's helper now serves both.CreateCommand,CreateTextCommandandCreateStoredProcedureCommandon aSqlTransactionwith no connection threwArgumentNullExceptionnamedconnection. They now throwInvalidOperationException("Transaction has no connection."), as Core does. A test and a release-notes bullet cover it.No public API change. The net line count is about even (+155 / -147): the saving is the four duplicated dispose blocks per file, which the two cores and their comments take back.
Checks
DbCommandoverloads, measured on this branch and on master with the same probe (bytes per call, handler completing synchronously): 112 on both, for every overload. With a handler that suspends, 407 against 403 and 439 against 436: a difference of 3 to 4 bytes a call, which is not a whole state-machine box (a multiple of 8), so it is measurement noise fromTask.Yield. The probe was scratch and is not in the PR; no existing allocation test covers these overloads.Review
Three read-only reviewers looked at the diff: correctness and allocation, minimalism and readability, and tests and docs.
#ifbranches; the two cores do not make overload resolution ambiguous; the lambdas capture nothing.ArgumentNullException: the release-notes bullet already says what it threw before and what it throws now.🤖 Generated with Claude Code