Skip to content

A return code on a text command follows ADO.NET (the SQL Server command refuses it), and MatchingOrdinals takes the first duplicate column - #323

Merged
electricessence merged 8 commits into
masterfrom
fix/ga-return-text
Dec 5, 2026
Merged

electricessence merged 8 commits into
masterfrom
fix/ga-return-text

Conversation

@electricessence

@electricessence electricessence commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

What

Two owner decisions for the 11.0.0 release, both behavior changes, each with a release-note bullet. The branch has the commits of both (squash to one).

1. A return code on a text command (A1-4)

Core now behaves as ADO.NET does and says so in the remarks; the strict check lives only in the SQL Server package.

  • Core: a return code read on a text command or a text definition no longer throws. ExecuteReturnAsync<T>() on a DbNonQuery.Text definition call, a ReturnValue member in ExecuteOutputAsync<TOut>() or Output<TOut>(), and a return-value capture (CaptureReturn, or a captured model with a ReturnValue member) ran into InvalidOperationException ("needs a stored procedure"); they now run and give what the provider reports (SQL Server: 0, and RETURN n in text is a server error).
  • SQL Server package: an ExpressiveSqlCommand whose type is text throws InvalidOperationException before a connection is used, for ExecuteReturn, ExecuteReturnAsync, ExecuteReturnAsync<T>, a ReturnValue member in ExecuteOutputAsync<TOut>() and a return capture. Before, ExecuteReturn* ran and gave 0. The message says to call the procedure by name or to use EXEC @r = dbo.p with an output parameter. A procedure called by name, and a definition run on a SqlConnection, are unchanged (definitions get remarks only).
  • ExecuteReturnAsync<T>() on a command now refuses at the call (an already canceled token, a capture of the return code beside the call, the refusals above), as ExecuteReturnAsync() already did, instead of from the returned task.
  • Dead code removed with the old rule (WithOnDefinition, two message consts). No public API change. The SQL Server refusal goes through an internal hook on the command base, also reached by the synchronous ExecuteReturn.

2. MatchingOrdinals takes the first column of a duplicated name (G3-1)

With duplicate column names, MatchingOrdinals(sort: false) gave the last column and sort: true gave all of them; both now give the first, as GetOrdinal does. Alias in SQL to read another. Dictionary.TryAdd gets an internal netstandard2.0 shim (in Compatibility), and RowMap uses it instead of its inline #if block.

Fail-first

  • A1-4: the tests of the removed throws failed first (each threw the old InvalidOperationException); the ad hoc ExecuteReturn on text was pinned as a test that runs both before and after.
  • G3-1: 4 of the 6 new tests failed before the fix (Expected: [(Id, 0)] Actual: [(Id, 0), (Id, 1)] for sorted, Actual: [(Id, 1)] for unsorted); the other two are pins.

Checks (head 816bda2)

  • Gate: Release and Debug builds 0 warnings, Core.Tests net11.0 Release 16280 passed (Debug 16259 passed, 16 skipped), VS MSBuild, dotnet format style and analyzers 0 findings, 267 sample checks, docfx 0 warnings.
  • Roslyn scan: 0 actionable. Roslynator: 0 findings on every project.
  • Style scan: two advisory lines, both internal members on public types (the new hook and the SQL Server override). Leak check over the whole diff and messages: clean.
  • Swarm (haiku lenses, arbitrated): the G3-1 change (correctness, owner rules, test gaps). Applied: shim braces and wrapping, three added tests and a literal expectation in the enumerate-twice test. Declined: a requested name given twice still yields twice in the unsorted mode (old behavior, not part of this change).

Not changed

Source/SqlClient (legacy, not published in v11). A definition run on a SqlConnection is not refused for a return code on text: the remarks say what SQL Server reports.

🤖 Generated with Claude Code

electricessence and others added 8 commits December 5, 2026 07:07
… definition

Old: ExecuteReturnAsync<T>() on a call of a text definition, a ReturnValue
member in ExecuteOutputAsync<TOut>() on a text command or in Output<TOut>()
on a text definition, and CaptureReturn (or a captured model with a
ReturnValue member) on a text command or a text definition threw
InvalidOperationException ("needs a stored procedure").
New: they run and give what the provider reports for a text command, as
ExecuteReturnAsync() on a text command always did. A provider package that is
certain can refuse it: a new internal hook on the command base, called before
anything runs by each call that reads a return code, does nothing in Core.

Reading the return code twice (a capture beside ExecuteReturnAsync) and a model
as the return code are still refused. The unused messages and the capture
set's definition-only entry point are removed; no public API changes.

The remarks of the return-code members, the article and the release notes say
what a text command gives and how to read a code from text (EXEC @r = dbo.p
with an output parameter). Tests that pinned the old refusals are replaced by
tests that run each path on a fake provider.

Behavior change: yes
Cost: none at run time; the hook is one virtual call per call that reads a
return code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Old: on an ExpressiveSqlCommand whose type is text, ExecuteReturnAsync(),
ExecuteReturnAsync<T>() and ExecuteReturn() ran and gave 0 (RETURN n in text
is a server error), and a ReturnValue member in ExecuteOutputAsync<TOut>() and
CaptureReturn threw a message about stored procedures.
New: all of them throw InvalidOperationException before a connection is opened
or taken, with a message that says to call the procedure by name with
StoredProcedure(name), or to read the code from text with EXEC @r = dbo.p and
an output parameter. A stored procedure called by name is unchanged.

The SQL Server package overrides the hook that Core's command base calls before
each call that reads a return code. The generic ExecuteReturnAsync<T>() now
starts the non-generic call at the call, so the refusal (and a capture beside
it, or a canceled token) is thrown at the call, not through the returned task,
as the non-generic form always did. A definition (DbNonQuery.Text on a
SqlConnection) is Core's and is not refused; the remarks say SQL Server reports
0 for it. The package lets the Core tests see its internal message constant.

Behavior change: yes
Cost: none at run time beyond one comparison of the command's type per call that
reads a return code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…the SQL Server command refuses a text command, and that ExecuteReturnAsync<T> refuses at the call

A definition run on a SqlConnection is not refused, so the shared remark names the command of the SQL Server package. The first release note no longer reads as if the SQL Server command also runs a return code on text, and a new item records that ExecuteReturnAsync<T>() on a command throws a canceled token, a capture beside it and the refusals from the call itself instead of from the returned task. A test name says what it checks.

Behavior change: no (documentation and a test name).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The Roslynator scan reports RCS1261 on the two async tests that built a connection with `using`; `await using` is what the rule asks for.

Behavior change: no (tests only).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…one column has

MatchingOrdinals with sort false kept the last column of a duplicated name
and with sort true returned all of them, so the two modes disagreed and
neither matched GetOrdinal. Both now return the first column of each
requested name, as ADO.NET GetOrdinal does.

Behavior change: yes.
Old: sort false gave the last duplicate, sort true gave every duplicate.
New: both give the first column of the name; alias in SQL to read another.

Dictionary.TryAdd gets an internal netstandard2.0 shim, and RowMap uses it
in place of its inline conditional block.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A method that declares Task<PooledArray<T>> can return the buffer itself
instead of buffer.Items. The conversion is the Items task (the same task on
every conversion), so a disposed buffer throws ObjectDisposedException as
Items does. A null buffer throws ArgumentNullException with a message that
says what to convert: Items does not guard null, so this is the only guard.
There is no GetAwaiter; the rows are still awaited through Items.

The ASP.NET Core controller sample returns the buffer, with the article text
and the release note. Five existing tests that passed a lambda returning a
PooledBuffer<T> to Assert.Throws or Record.Exception now use a statement
lambda: a lambda that returns a buffer now also converts to Func<Task>, and
xUnit refuses that overload.

Behavior change: source level only. A lambda or argument whose type is a
PooledBuffer<T> now also converts to Task<PooledArray<T>>, so an overload set
that has a Func<Task> or Task parameter can bind to it where it did not.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The implicit conversion changes overload resolution for every argument or
lambda of type PooledBuffer<T> (it can now bind to a Func<Task> or Task
overload), which is not worth saving a call of Items. Removes the operator,
its PublicAPI entry, its release note, the article and sample change, its
tests, and puts back the five lambdas that the conversion made cast to
Action.

Behavior change: none against the last release; this undoes an addition that
was never released.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@electricessence electricessence changed the title A return code on a text command follows ADO.NET (SQL Server command refuses), MatchingOrdinals takes the first duplicate column, PooledBuffer<T> converts to Task<PooledArray<T>> A return code on a text command follows ADO.NET (the SQL Server command refuses it), and MatchingOrdinals takes the first duplicate column Dec 5, 2026
@electricessence
electricessence merged commit 65c2b09 into master Dec 5, 2026
9 checks passed
@electricessence
electricessence deleted the fix/ga-return-text branch December 5, 2026 18:13
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