DynamicParameters.AddParameters(IDbCommand): identity-free self-apply - #2225
Merged
Conversation
The full bag protocol (per-parameter DbType/direction/size, templates, literal replacement, RemoveUnused) already lives in AddParameters(command, identity), but the identity requirement makes it uncallable from outside: Identity's constructor is internal, and identity.Sql is consumed on the first line. This overload builds the identity from the command's own text and type, which is what identity.Sql is in practice - letting external tooling (for example build-time code generators, aka Dapper.AOT) apply a bag without reimplementing the protocol. Test covers the bag+literal composition against a closed connection (no database needed).
This was referenced Aug 18, 2026
A subclass that hides AddParameters and re-implements the interface - the DynamicParameterWithIntTVP pattern from this very test suite - was skipped by the direct call, which binds statically to the protected base method. Routing through the interface uses the runtime type's interface map, so the subclass version runs, matching what vanilla execution does.
Member
Author
|
Pushed a follow-up: the overload now dispatches via |
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.
The full bag protocol — per-parameter
DbType/direction/size/precision/scale, templates, literal replacement,RemoveUnused— already lives inAddParameters(command, identity), but the identity requirement makes it uncallable from outside:Identity's constructor is internal, andidentity.Sqlis consumed on the first line. This overload builds the identity from the command's own text and type (which is whatidentity.Sqlis in practice), letting external tooling apply a parameter bag without reimplementing the protocol.The immediate consumer is Dapper.AOT: its generated command factories can now support
DynamicParametersarguments by delegating to the bag itself — which gives exact vanilla behavior for the whole surface (includingGet<T>output reads andIParameterCallbacks) because it is the vanilla implementation. The generator probes for this symbol, so it activates only when the referenced Dapper has it; no coordination needed on release timing.Test covers the bag + literal-replacement composition against a closed connection (no database needed). API registered in
PublicAPI.Unshipped.txt.