Repository navigation
Output parameters: ExecuteOutputAsync, and parameter directions off the fluent chain - #290
Merged
Merged
Conversation
AddParam and AddParamIf no longer take a ParameterDirection, the overloads that took only a type or only a direction are gone, and so are AddReturnParam and the SQL Server DbType-and-direction overloads. A parameter on the chain is an input; a direction is set with the raw AddParameter, AddParameterType and AddReturnParameter extensions inside ExecuteAsync(command => ...), which are unchanged. Calls that never passed a direction compile unchanged. Tests of the removed API are deleted, the PublicAPI files and docs are updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Param loses its direction constructor parameter and its Direction property, and a null value is always stored as a database null. The readers of the direction in the command classes are simplified to treat every parameter as an input, and the SQL Server commands no longer have a branch for a parameter with no value. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ExecuteOutputAsync<TOut>() on the expressive commands runs the command and maps its output parameters and return code into a model by name, with the Map<T>() rules (the runtime map, never a generated reader). ExecuteOutputAsync<T>(name) reads one value. A decimal needs its precision and scale, or the server rounds it to a whole number: [Column(TypeName = "decimal(p,s)")] on a member, or ExecuteOutputDecimalAsync(name, precision, scale) and ExecuteOutputAsync<decimal>(name, precision, scale) for one value. Members match parameters as AddParam(value) does when the names are known, [Column("name")] exactly, and a ReturnValue member reads a procedure's return code. A member whose parameter got a value is sent as InputOutput, any other as Output. DateTime goes as DateTime2, strings and binary with size -1. Core adds the parameters itself after the provider's, per call, never on the command; an output that never arrived throws instead of reading as NULL. Every error names the member, parameter or type, says what is wrong, and gives the fix. ExecuteReturnAsync<T> refuses a model type at the call. Calls without outputs keep their path: one type compare of the run's state. No blocking form (owner decision).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AddParam(name, direction), AddParamIf(condition, name, direction), AddParam(name, type) and AddParamIf(condition, name, type) would otherwise still compile and send the enum as the value. They are now kept as obsolete-as-error overloads that explain what to do instead, and throw NotSupportedException if reached by reflection. Stale docs about output parameters are corrected, and a test keeps the check that derived-name parameters carry no direction. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… review fixes. DateOnly is sent as Date and TimeOnly as Time (nullable forms included) and read back by the row conversion. A legacy datetime output reading .9966667 is documented with its remedy (SqlDateTime, or datetime2(3)) and pinned by tests. The decimal shape overload guards its arguments once, the shape message only suggests calls that work for the type, ExecuteOutputAsync<TOut> documents when it completes and links the named and decimal forms, and a not-delivered output wins over a conversion failure. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… note the byte-zero call. TheCorePackage_ShipsNothingObsolete now exempts only the AddParam/AddParamIf compile-error overloads on ExpressiveCommandBase and asserts there are exactly four, so any other obsolete member still fails it. The release notes say that AddParam(name, (byte)0) on the SQL Server command, which used to bind silently to the direction overload, is now an ambiguous-call error, and what to write instead. The derived-name test is renamed to say what it checks: the chain sets no direction, so a parameter keeps the provider's default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in the reader ToArrayAsync and ToImmutableArrayAsync, copy-out clearing, the synchronous ToList on pooled chunks, and the benchmark changes. Conflicts were only in PublicAPI.Unshipped.txt and release-notes.md, where both sides added lines; both are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… findings. Documents the placeholder-null InputOutput limit, the removed three-argument direction forms, that ValueMappingException is thrown after the command ran, the ReturnValue name in the named forms and the synchronous cancel check. Renames the decimal refusal member, names the call in the no-match message, builds the ambiguity fix text only when it throws, and removes the unused MatchBare. Tests: conversion-vs-not-delivered ordering, char outputs, the cancel-during SqlException, and the analyzer and style findings (CA2012, CA1822, xUnit1045, IDE0022, IDE0032, IDE0056, IDE0057, CA2012 in the decimal form). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A char member or ExecuteOutputAsync<char> declares the output with size 1, so a char(3) holding XYZ reads X without an error, as the model type asks; a string reads the whole value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ExecuteOutputAsync forms, ExecuteOutputDecimalAsync and ExecuteReturnAsync now pull their shared facts (what the task returns, the name rules, the decimal shape and why, the legacy datetime note, the not-delivered and after-the-run failures, the cancel sentence) from one docs.xml file, and the generic decimal shape form inherits the remarks of ExecuteOutputDecimalAsync. Keys for the capture members are added for the next part. Docs only: no behaviour, signature or message changes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Adds compiled samples (docsite/samples/OutputParameters.cs) for ExecuteOutputAsync into a model with a ReturnValue member, one named value, decimal outputs, and raw output and return parameters inside ExecuteAsync. The expressive-commands article shows them in place of the inline block. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The named ExecuteOutputAsync form states the DateTime2 note; the decimal forms say the value converts as Map<T>() does; the decimal [Column] fact has one wording. The decimal sample shows the model only; the single-value decimal calls sit in the named sample. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The named and raw snippets used a local factory while the model and decimal snippets used the shared one; all four now read the same name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CaptureOutput (a model, one value, or a decimal with its precision and scale), CaptureOutputDecimal and CaptureReturn on an expressive command, a mapped query and its Skip and Take views. Each gives a DbCapture<T> as an out argument; the query's async terminal fills it after the reader is closed, and a stream fills it when its loop ends, a break included. - DbCapture<T>: a readonly struct with GetAwaiter, ConfigureAwait and AsTask only; its GetResult throws while the capture is pending, never blocks. Awaiting before the terminal, inside the stream's own loop, or a default value throws with the fix. - One run: the claim is a compare-exchange on the set's first source, so Map<T>() shares the command's capture and the first run wins; a second run throws. - The command's run passes the captures' layout as an OutputRun, so the parameters are added exactly as ExecuteOutputAsync adds them. - Refused, with the capture completed by the refusal: a synchronous terminal (arms nothing), ExecuteAsync(command => ...), ExecuteOutputAsync beside a capture, ExecuteReturnAsync beside CaptureReturn, CancelOnEarlyStop(), a query from a DbQuery definition or from another IExecuteReader (C2 adds the definition forms). - Streams and the pooled buffer: an early stop by the consumer no longer cancels a captured read (DirectStream, StallStream, ChunkProducer; StreamTarget refuses a publish once disposed), so the outputs arrive. A cancel of the caller's still cancels it. - Every exit completes every armed capture: value, fault, cancel with the caller's token, or "not delivered". Tests: CaptureTests (fake provider), 38 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three samples in OutputParameters.cs, pulled into the expressive commands article under "Output parameters beside rows": a capture beside ToListAsync, CaptureReturn on the command before Map, and a stream whose capture is awaited after the loop. The article says the definition form is the recommended one, that captures on it come in a later commit of this pull request, and that a capture is per call. One bullet each in What's new and the release notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CA2016 at info severity: the capture stream sample now forwards its cancellation token to the writer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
electricessence
marked this pull request as ready for review
December 2, 2026 13:36
…rm at the call A command that re-implements IExecuteReader can no longer leave a capture pending. A query with a capture (its own or its command's) runs through the command's own reader path, and the synchronous path refuses it as before. The Channel and Dataflow feeds take the stream's enumerator before their first await, so the capture is claimed at the call. Then they wait for room in the channel, or check that the block has not finished. A target closed before the first row runs nothing, and the capture says so: "the query never ran: ... its target closed". The stall signal of StreamBuffered is now seen through the capture's stream wrapper, so a stall while the target has no room still ends the pass with a TimeoutException. The docs say that a fault only the capture carries (a conversion, outputs not delivered) is reported only there. Tests: - The fake provider moves to TestHelpers/CaptureProvider.cs. It can now fail a run, and its gate honors the token. - CaptureStreamTests: a failed run; a stall; a cancel while the command runs, on every stream; a second enumeration; a PooledBuffer disposed mid-read or given a canceled token; every Channel and Dataflow member arming at its call; a closed channel, a finished block, a full channel, a cancel while waiting for room, a target closed after the first row, a stall through the wrapper; a command that re-implements its reader; a null transform throwing before anything is armed. - CaptureLocalDbTests (SQL Server LocalDB): rows with an output and the return code; an early stop on every stream and the buffer still delivers; a later error faults the capture with the same SqlException; a cancel mid-read; a model with a decimal; a text command's output marker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A null transform passed to ExecuteScalarAsync<T> now faults the task without arming the command's capture, so the capture says it has not started instead of being faulted. This follows the rule that every exit completes every armed capture, while argument, layout and shape guards arm nothing. The helper that faulted the capture for that guard is gone. The Channel and Dataflow pumps open their stream without an async frame: when the channel has room, or the block is open, the enumerator comes back in a completed task with nothing allocated. When the channel wait fails, a failure to dispose the unread stream no longer replaces the wait's exception, so a cancel stays a cancel. The message for a capture on a query from a DbQuery definition now says what to do, without naming a release. Repeated comments are cut, the comment on an early stop names how the outputs arrive (the provider's close of the reader drains the response), and the byte order mark of ExpressiveDbCommandBase.cs is back. The docs now say that an early stop waits for the server to finish sending, which the stall timeout does not bound, and that FirstAsync or SingleAsync with no rows still fills the capture. New tests: a SingleResult() read on LocalDB (one row asked for, no read-through) delivers the output; FirstAsync and SingleAsync with no rows throw and still fill the capture; AnyAsync and CountAsync on a command fill its capture and give the command's second-run message; a null transform and a bad ExecuteOutputAsync argument arm nothing; a capture added to the command after Map() is filled; a pooled buffer whose scheduler refuses the start faults its capture; a canceled channel wait is not replaced by a failed dispose; ToBoundedChannel arms at the call; CaptureOutput<decimal?> without a precision and scale is refused at the call. The pooled buffer test now disposes after the first chunk, the unobserved-fault test has a positive control, and the null-transform test awaits its ValueTask (CA2012). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test stopped collecting as soon as the positive control was reported, so the capture it checks might not have been finalized yet and the test could pass without checking it. Two more collection rounds follow the control. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Master replaced the four switch flags of a mapped query with one QueryOptions value and added WithOptions. The query core keeps that shape and carries its capture set as before: every copy (WithOptions, WithConfig, WithSkip, WithTake, the capture and run copies) passes it on, equality and the hash include it, and WithCall still refuses a query that carries a capture. PublicAPI.Unshipped lists both sides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner direction: the feeds dispose their enumerator with await using instead of a try/finally whose finally only disposes (ChunkFeed and RowFeed in ChannelPump and in BlockPump). The dispose still runs on every exit and an exception from it still replaces the loop's, as the finally did. The catch in ChannelPump.OpenAsync stays: it must not let a failed dispose replace the wait's exception. Owner direction: show by test that the wait for room belongs in ChannelPump.Open. For both Channel members, a full bounded channel opens no connection and runs no command until a row is taken (then the command runs once and every row arrives), and a channel that closes while full returns 0 with nothing opened. Dataflow has no wait for room; its tests pin the closed-at-call check for both feeds (completed and faulted: no command), that a full block still runs the command once and delivers every row, and that a block that completes while full still runs the command and returns 0, the documented difference from Channel. One test per stream class a pump can receive (ChunkStream, StallStream, and the capture wrapper over each): taking the enumerator and disposing it runs no command and opens no connection. A capture on a mapped query and on the skip view survives WithOptions. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
expressive-commands.md no longer points at a later commit for captures on a definition: a query made from a definition does not take a capture. The release notes name both exceptions a capture call can throw: NotSupportedException on a query made from a definition or one that does not read from an expressive command, InvalidOperationException otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
electricessence
had a problem deploying
to
github-pages
December 2, 2026 16:25 — with
GitHub Actions
Failure
This branch had an error being deployed
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.
Output parameters for the expressive commands, targeting 11.0.0-rc.17: parameter directions leave the fluent chain, outputs and the return code are read into a model or one value, and captures read them beside the rows of a mapped query.
What changes
Parameter directions leave the fluent chain (breaking).
AddParamandAddParamIfno longer take aParameterDirection, andAddReturnParamis removed. A parameter added on the chain is an input; the publicParamis input-only.AddParam(name, ParameterDirection),AddParam(name, TDbType)and theirAddParamIfforms (hidden[Obsolete(error: true)]overloads).AddParameter(..., direction)andAddReturnParameter()insideExecuteAsync(command => ...)stay.Reading outputs.
ExecuteOutputAsync<TOut>()runs the command and maps its output parameters and return code into a model by name, with theMap<T>()rules. AReturnValuemember reads the return code.ExecuteOutputAsync<T>(name)reads one output value; the name is matched exactly (ignoring case, with or without@).decimalneeds its precision and scale, or the server rounds it to a whole number:[Column(TypeName = "decimal(p,s)")]on a member, orExecuteOutputAsync<decimal>(name, precision, scale)/ExecuteOutputDecimalAsync(name, precision, scale)for one value.DateTimeis sent asDateTime2, strings and binary with size -1,DateOnlyasDate,TimeOnlyasTime.Outputs beside rows: captures.
CaptureOutput(out DbCapture<TOut>)(a model),CaptureOutput<T>(name, out …)(one value), the decimal forms (CaptureOutput<T>(name, precision, scale, out …),CaptureOutputDecimal) andCaptureReturn<T>(out …), on the command and on mapped queries (includingSkip/Take). The query's async terminal fills the capture; await it after the terminal.First/Singleand theirOrDefaultforms (also when they throw for no rows),AnyAsync/CountAsync, streams, pooled buffers, and the Channel and Dataflow members.breakincluded (closing the reader drains the response); awaiting the capture inside the loop throws.DbCapture<T>is awaited only and never blocks. A chain that carries a capture runs once; a second run throws. Calls without a capture pay one null check per terminal run.sql_server_output_capture_*indocsite/samples/OutputParameters.cs, shown in the expressive-commands article.Every error names the member, parameter or type, says what is wrong, and gives the fix. Shared doc text lives in
Source/Core/Output.docs.xml; compiled examples indocsite/samples/OutputParameters.cs.Channel and Dataflow targets.
Skipview survivesWithOptions.Decided by the owner
ExecuteOutputmethods.ExecuteOutputDecimalAsync(alwaysdecimal?, checked by the compiler) andExecuteOutputAsync<decimal>(name, precision, scale)(Tdecides NULL handling, checked at the call). Precision and scale arebyte.DateOnlyandTimeOnlyoutputs supported.datetimeoutput read intoDateTimegives the exact stored value throughdatetime2(.997reads.9966667, where a row read gives.997). Documented with the remedy (new SqlDateTime(value).Value, ordatetime2(3)in the procedure); no behaviour based on procedure metadata.Map<T>()shares a command's capture with the query, and the first run claims it (a capture added to the command afterMap<T>()is still seen, unless the query carries its own; see Known issues); a command that carries a capture runs once, and a second run throws; a capture andExecuteOutputAsyncon the same command are refused together.Assumed, owner to confirm (each easy to flip)
Paramis input-only (own commit).ReturnValuemember as well asExecuteReturnAsync<T>();ExecuteReturnAsync<T>now refuses a model type at the call.AddParam(name, (byte)0)on the SQL Server command, which used to bind to the direction overload, is now an ambiguous-call error (CS0121); the release notes say what to write instead."ReturnValue"names a declared parameter, never the return code.ExecuteReturnAsyncdoes.charoutput is declared with size 1, so it reads one character (achar(3)holdingXYZreadsX, no error); astringreads the whole value. Documented.decimal?captured by name without a precision and scale is refused at the call, likedecimal.Known issues (fixed in the follow-up)
IExecuteReaderis not refused: the captured run uses the library's reader, so the subclass's own reader logic is skipped.break,AnyAsync) reads the rest of the response so every output arrives, with no limit on how long that takes; on a slow or stalled server without a stall timeout, the loop's exit waits for it.TimeoutExceptionmessage.Follow-up pull request
Output<TOut>()onDbNonQuerydefinitions, and captures on calls made from a stored definition.AddParamuses), and capture names taken from the variable. Decided, not in this pull request.Tests
Real database: SQL Server LocalDB, procedures created per test in
tempdbunder unique names and dropped after; the gate sets the variable that turns a missing server into a failure. Unit tests use a recording fake provider. Full suite at the head: Debug 15,884 passed, 16 Release-only skipped; Release 15,904 of 15,905 passed. The one Release failure isSyncToListAllocationProbeat 100,000 rows, an allocation probe already on master that fails intermittently on its own build too (2 of 20 runs there, 4 of 20 here); it is not touched by this change.EachType_AsAModelMember_IsRead,EachType_AsANamedValue_IsRead_ADecimalByItsPrecisionAndScale,AnOutputOnlyCall_SendsEachMemberAsAnOutput_AndReadsTheModel,TheNamedForm_MatchesTheNameExactlyReturnOnly_ReadsTheReturnCode_AsEachType_AndIntoAModel(int,int?,long, enum),TheReturnCode_IsOneIntegerAReturnValueMember_ReadsTheReturnCode(LocalDB and fake),ADeclaredReturnValue_AndAReturnValueMember_Throw_AndColumnReadsTheParameterAnInputOutput_ReadsBackTheValueTheProcedureSet,AnInputOutputString_IsNotCutToTheValueSent,AMemberWhoseParameterGotAValue_IsSentAsInputOutput_UnderTheNameAsWrittenNullOutputs_AreNullWhereNullable_AndAnErrorWhereNot,Null_IsNullInANullableMember_AndAnErrorInANonNullableOneALaterStatementsError_ThatTheProviderDoesNotThrow_IsNotDelivered,AnOutputThatNeverArrived_Throws_NeverReadsAsNull,NotDelivered_WinsOverAConversionFailureAConversionFailure_InDotNet_IsAValueMappingException,AConversionFailure_OnTheServer_IsTheProvidersErrorCancel_BeforeAndDuring,ACanceledToken_ThrowsBeforeAnythingRunsTheDecimalForms_ReadADecimal_ByItsPrecisionAndScale,ADecimal_TakesItsTypeName_OutputAndInputOutput,TheDecimalForms_SendThePrecisionAndScale_AndTDecidesNull,TheDecimalForms_RefuseAPrecisionOrScaleOutOfRange_OrAnotherType_AtTheCallTimeTypes_WithNoShapeSet_ReadBackExactly(time(7),datetime2(7),datetimeoffset(7)),ADateTime_IsExact_InADatetime2_IncludingYearOne,DateOnlyAndTimeOnly_ReadBackExactly,ALegacySmallDateTime_ReadsBackExactly,ALegacyDateTime_ReadsBackAsItsDateTime2Value_ADocumentedLimit,ALegacyDateTimeOutput_FedBackAsAnInput_LandsOnTheSameStoredTick,ASqlDateTime_GivesTheValueARowReadGivesStringsAndBinary_ComeBackWhole,OtherTypes_ReadBackExactly_AndACharIsPadded(long,bool,double,char(n)intostring), thechartests (model member andExecuteOutputAsync<char>)WhenTheNamesAreKnown_NoMatchAndTwoMembersOnOneParameter_ThrowBeforeTheRun,TheNamedForms_RequireAName_First,AModelThatCannotBeRead_ThrowsAtTheCall,AReturnValueMember_OnATextCommand_ThrowsAtTheCallAnOutputOnAnInputOnlyParameter_IsTheProvidersError_AndTheNamesAreForgotten,SQLite_RefusesAnOutput_WithItsOwnErrorTheRows_AnOutput_AndTheReturnCode,ASingleRowRead_StillDelivers,ALaterError_FaultsIt_WithTheProvidersError,AModel_WithADecimal_AndTheNamedDecimal,ATextCommand_FillsItThroughItsMarkerCaptureTests(terminals, single run, refusals, arming),CaptureStreamTests(streams,break, pooled buffers, Channel and Dataflow: closed, finished, full, canceled, stall timeout)ChainTrapOverloadTests,TheCorePackage_ShipsNothingObsolete(exempts exactly the four)tempdbuses the server's collation, so a case-sensitive database is not covered.Reviews
The plan was reviewed before the build. Each part was checked against its plan after the build and reviewed by several independent reviewers, with each finding challenged and arbitrated. The whole change was reviewed again before merge. No blocking findings remain; their fixes are in.
🤖 Generated with Claude Code