Repository navigation
Seven fixes for a production consumer's rc.1 feedback: a late SQL error was swallowed, generic commands dropped a parameter's direction, AddParams(object) sent nothing, Map<Dictionary> returned an empty row, the DbType overload trap, parameter names through IDbConnectionFactory<DbConnection> and on SQL text - #84
Closed
electricessence wants to merge 20 commits into
Closed
electricessence wants to merge 20 commits into
electricessence wants to merge 20 commits into
Conversation
… source
SELECT 1; RAISERROR('late', 16, 1); completes with the row today: the read loops stop at the last row, and a provider reports an error that follows the rows only when the reader moves on.
LateErrorTests uses a reader whose NextResult (and NextResultAsync) throws, like a provider does for such an error, and asserts for every MappedQuery terminal (sync and async), the command-level Results and Retrieve, and the Channel and Dataflow pipelines that the error reaches the caller (and faults the target when complete is true); that First, Single and Take(n) read one more row to find the end of the rows and stop there when there is one; that a streaming handler that stops early is not drained; and that the reader-level helpers on a reader the caller holds leave it where it stopped. TypedReader counts NextResult calls and can be told to throw from it. Two RowMapperTests that counted the rows read now expect the one extra row.
101 of the 140 tests in LateErrorTests and RowMapperTests fail on the unfixed source.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…m 2 of the consumer feedback) ExpressiveCommand and ExpressiveDbCommand never set the Direction of the provider parameter, so Output, InputOutput and ReturnValue parameters reach the database as inputs. These tests read the direction on the provider's parameter for all four directions, sync and async, a NULL-valued output parameter, and a mixed call; they fail until the fix. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…direction (item 2 of the consumer feedback) AddParams on the generic commands never set the Direction of the provider parameter, so an Output, InputOutput or ReturnValue parameter reached the database as an input and a procedure with an output parameter failed with "expects parameter '@o', which was not supplied". The direction is now set, as the SQL Server command already did. Passes the tests added in the previous commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…failing: item 3 of the consumer feedback)
On the SQL Server commands the database type is SqlDbType, so AddParam("@o", DbType.Int32, ParameterDirection.Output) binds to the object overload and the enum becomes the VALUE of an output parameter. These tests, written for both packages through an extern alias, expect a typed parameter with no value; the four that need the new overload fail, and the three that pin the calls which must keep their meaning (a literal 0 above all) pass.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…parameter names through the ProcedureParameters schema collection
ExpressiveDbCommand, and ExpressiveCommand over a DbConnection, should find the real names (AddParam(orderId) as the declared order_id, a member the procedure
does not declare dropped from AddParams) through GetSchema("ProcedureParameters"): the restrictions asked for one-, two- and three-part names, the ordinal-0 return
value skipped, rows in ordinal order, an ambiguous name across schemas, a provider without the collection, a database error carrying the procedure name, and
the names remembered like the other lookups. The fake provider answers with a DataTable that has the columns of INFORMATION_SCHEMA.PARAMETERS. 24 of the 35 fail
until the lookup exists; the rest pin today's "not known" outcomes.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…L Server commands (item 3 of the consumer feedback)
ExpressiveSqlCommand in both SQL Server packages takes AddParam(string, DbType, ParameterDirection) and the AddParamIf twin, so AddParam("@o", DbType.Int32, ParameterDirection.Output) adds an Int output parameter with no value instead of an output parameter whose value is the enum. The DbType is converted to the SqlDbType the provider maps it to.
The direction has no default on purpose: an overload declared on the command hides the inherited ones wherever it applies, and a literal 0 converts to any enum, so with a default AddParam("@count", 0) would have bound to it and added a typed NULL. The tests of the previous commit pin that call, and the alias on the SQL Server package reference lets the test project reach the real commands of both packages.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…eader terminal After the natural end of the rows (a Read returned false) every terminal now calls NextResult once (NextResultAsync when it reads asynchronously), which is what makes a provider raise an error that follows the rows. This covers the Map<T>() terminals (list, array, immutable array, dictionary, hash set, first, single, and the Read and ReadAsync handlers that enumerate to the end), Results and Retrieve on commands, and the Channel and Dataflow pipelines, where the error faults the target when complete is true. First, single and Take(n) read one more row after the wanted rows: no row is the end (NextResult), a row means stop there without reading the rest. A handler that stops early is not drained. Reader-level helpers on a reader the caller holds (Results(reader), ResultsBuffered(reader), ...) leave it where it stopped, so a caller may still read the next result set. Measured with the consumer probe against SQL Server LocalDB: raw SqlClient with the default behavior and NextResult throws the error; with SingleResult|SequentialAccess, NextResult and Dispose complete without it; with SingleRow it is not raised either. The terminals therefore no longer request SingleResult (Map<T>() keeps SequentialAccess for generated mappings) or SingleRow. With that, every late-error line of the probe passes. Cost: one NextResult call per query and, for first and take, one more Read; no allocation (the allocation tests are unchanged). mapping.md states the new behavior. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…em 4 of the consumer feedback) A variable or a Func<T, object> result typed object has no members of its own, so AddParams(x) sent nothing and the procedure ran with every parameter NULL. These tests expect the members of the runtime type: an anonymous object, a Func result read at every call, different runtime types in a row, a struct, a type with no members, a null source, a throwing getter, and a ref-struct member skipped on that path. The static-type rule for every other type is pinned beside them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e type (item 4 of the consumer feedback) A Func<T, object> result or an object variable has no members of its own, so AddParams sent nothing and the procedure ran with every parameter NULL, with no error. When the static type is exactly object, the public readable properties and fields of the runtime type are used (as Dapper does); every other static type keeps its own members. A non-generic table keeps one immutable entry per runtime type, with a compiled getter per member that takes the object, so no reflection runs after the first time a type is seen; the table is weak, so an unloaded type takes its entry with it. A null source still throws ArgumentNullException. A member whose type cannot be boxed (a ref struct such as ReadOnlySpan<char>, or a pointer) made the static-type path throw TypeInitializationException for that type; the new path skips such members. The static-type path is unchanged. The AddParams remarks and the expressive-commands page say so. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…es through the ADO.NET schema collection
ExpressiveDbCommand (and ExpressiveCommand when the connection is a DbConnection) now override GetProcedureParameterNames and its async twin with a shared helper
that calls GetSchema("ProcedureParameters"): AddParam(orderId) finds @order_id and AddParams(new { ... }) drops the members the procedure does not declare on a
command made from an IDbConnectionFactory<DbConnection>, which SQL Server answers. The name is split into schema and name (brackets and quotes removed); a name with
a database part, an empty part, a provider without the collection, and a name found in more than one schema when none was given are "not known" (used as written).
A database error is thrown as it is with the procedure's name in Exception.Data["Procedure"]. The result goes through the same remembered-names path as the SQL
packages' lookup, which is unchanged. Checked on SQL Server LocalDB, also inside a transaction: it neither throws nor commits.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@name tokens The tokenizer table first (strings and '' escapes, "" and [] identifiers with their escapes, line and block comments, @@System variables, names with digits, _, $ and #, an @ with no name, an address-looking text inside a string, repeated names, names in another case), then derived names on a CommandType.Text command through ExpressiveCommand, ExpressiveDbCommand and its async path: the four tiers, ambiguity, no match, a name only in a string or comment, a collision, no token (kept as written), TableDirect and stored procedures untouched, AddParams dropping undeclared members, an explicit name winning. 85 of them fail until the tokenizer exists. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…em 5 of the consumer feedback) Map<Dictionary<string, object?>>() and Map<ExpandoObject>() return one empty row and say nothing, because the types have a public parameterless constructor and no properties to set. These tests expect the InvalidOperationException a type that cannot be mapped gets, at the call, even for an empty result, on every entry point and for every way a type is a dictionary (IDictionary, IDictionary<,>, IReadOnlyDictionary<,>) or a dynamic object (IDynamicMetaObjectProvider); an interface keeps its own reason and a model that merely holds a dictionary still maps. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…() (item 5 of the consumer feedback) Map<Dictionary<string, object?>>() and Map<ExpandoObject>() returned one empty row with no error: the types have a public parameterless constructor and no properties to set. They are not row models, so Shape.Judge now rejects any type assignable to IDictionary, to a closed IDictionary<,> or IReadOnlyDictionary<,>, or to IDynamicMetaObjectProvider, with an InvalidOperationException at the call, even for an empty result. An interface or an abstract type keeps its own reason, and a model that merely holds a dictionary still maps. The RowMap<T> remarks and the mapping page list the new case. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…its SQL text For a command of CommandType.Text the "declared names" are now the @name tokens in the command text, matched with the same four tiers as the parameters of a stored procedure (on ExpressiveCommand, ExpressiveDbCommand and ExpressiveSqlCommand, sync and async), so AddParam(regionId) on "... WHERE region_id = @region_id" sends @region_id and AddParams(new { ... }) sends only the members the text uses. The internal tokenizer (SqlTextParameters) returns the distinct tokens in order of first appearance (the same name in another case once) and skips single-quoted strings, double-quoted and [bracketed] identifiers, -- and /* */ comments and @@System variables; only @ is recognised. The result is remembered per command text (at most 256 texts, then the cache starts again). A text with no @name token keeps the argument's name as written, so nothing that works today changes; ambiguity and no match throw the same InvalidOperationException as for a procedure. Three existing tests that pinned "a text command with @ in it uses the name as written" now use a text without a marker (or expect the marker). Docs: the expressive-commands article, the AddParam/AddParams XML remarks and the MSSqlClient README line. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nge instead of Substring, CA2249 Contains where the target has it) The full gate listed both at --severity info after the two items; no behavior change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… the new code (naming, an unused using, a local function, const locals, class bodies, one dismissal with its reason) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…unmappable list and the limits Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This was referenced Nov 9, 2026
Collaborator
Author
|
Included in #85, which now targets master and contains these commits plus the later fixes. |
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.
Seven fixes for a production consumer's rc.1 feedback (a late SQL error was swallowed, generic commands dropped a parameter's direction,
AddParams(object)sent nothing,Map<Dictionary>returned an empty row, theDbTypeoverload trap, parameter names through anIDbConnectionFactory<DbConnection>and on SQL text), each with tests that fail first, and the release notes updated.A production SQL Server app is moving from Dapper to ODE 11 and measured rc.1 against LocalDB with Dapper side by side. Five of its ten findings were defects and two were gaps that matter for its setup; you asked me to fix everything that needed it. The work was split over three agents on three branches (a branch per area, tests first, one commit pair per item); I merged them (no conflicts), reran everything on the merge, and fixed what the gate found. Branch
integration/rc2on master 41af17c.What was wrong and what changed
SELECT 1; RAISERROR('late', 16, 1);read withMap<T>()completes with the row; Dapper throwsSqlExceptionSingleResultorSingleRowNextResultcompletes silentlyMap<T>()terminal,Results,Retrieveand the Channel and Dataflow pipelines callNextResultonce (the error faults the target whencompleteis true);FirstOrDefault,SingleOrDefaultandTake(n)read one more row to find the end and stop without reading more when there is one; a handler that stops early is not drained; the mapped terminals no longer requestSingleResult(orSingleRow)IDbConnectionFactory<DbConnection>fails ("expects parameter ... which was not supplied")ExpressiveCommandandExpressiveDbCommandnever setDirectionAddParam("@i", DbType.Int32, ParameterDirection.Output)binds the enum as the valueSqlDbType)AddParam(name, DbType, direction)andAddParamIfin both SQL packages (no default fordirection, which would hijackAddParam("@count", 0))AddParams(x)withxtypedobjectsends nothing; the procedure runs with every parameter NULLMap<Dictionary<string, object?>>()andMap<ExpandoObject>()return one empty rowInvalidOperationExceptionat the call, likeMap<int>()AddParam(orderId)is sent asorderId;AddParamssends members the procedure does not declareDbConnectionthrough the ADO.NETProcedureParametersschema collection (SQL Server supports it; other providers keep "as written"); it works inside a transaction and is cached like the SQL packages' lookupAddParam(regionId)on... WHERE region_id = @region_idfails at the server@namemarkers of the SQL text are the declared names, with the same four tiers; no marker keeps the name as writtenItems 7 to 10 of the consumer's list (output values after the call, a column-name selector, tokens on the scalar terminals plus
AnyAsync/FirstAsync/SingleAsync, width conversion inExecuteScalar<T>) are additive API and not defects; they are for later, the last one is documented as an exact cast.Verification (gentle: BelowNormal, 2 cores)
The gate (
verify-gate.ps1) on the merge, then the scans:EnforceCodeStyleInBuild=true: Release 0 warnings 0 errors; Debug 0 warnings 0 errors.dotnet format styleandanalyzers,--severity info: 0 findings in all nine projects after one style commit. The gate found 9 inRuntimeParamSource(three field names that need a_prefix, counted per target framework) and 2 in a test file; the three fields are properties now, and the rescan confirms 0 and 0 onCoreandCore.Tests.IDE0370where the!is needed in Release, oneIDE0078sample pattern); the merge had 7 more in the new code (naming, an unused using, a local function, anew()simplification, an xUnit serialization warning), all fixed. Roslynator: 0 findings in all ten projects (the merge had 25 in the new tests: 22 locals that never change areconstnow, two empty class bodies became;, and one local stays a variable on purpose, with the reason next to it: a literal 0 converts to any enum, a variable does not).Not done / decisions for the owner
reader.Select(transform):First,Take,Skip,ToList(transform),IterateReader,FirstOrdinalResults,LoadTable, ...) are unchanged and some requestSingleRow | SingleResult, which hides the late error from SqlClient. They need the same treatment if you want them covered; the notes say so.ToTargetBlock(reader)andToChannel(reader)move the caller's reader to its end (the command-level calls are built on them); a laterNextResultby the caller would skip a result set.Take(n)orFirstthat stops with rows left does not drain them, so an error that follows many rows is not seen by those calls.AddParam("@o", ParameterDirection.Output)) fails in SqlClient ("invalid size of 0"), through the SQL package too: an output parameter needs a type (and a size for a string); the notes already say so. The two-argumentAddParam("@i", DbType.Int32)still binds a value.NotSupportedException,ArgumentException,NotImplementedException, or anInvalidOperationExceptionwhose message mentionsProcedureParameters; the tokenizer treats adeclare @xlocal like any@name, keeps the first spelling of a name that appears in two cases, and reads@a@bas two names; for a text command the no-match messages still say "the procedure declares".PublicAPI.Unshipped.txthas three newoverridelines (the lookup on the two generic commands).@Namesends the name as written", which is exactly what item 6 changes.🤖 Generated with Claude Code