Preserve Size set by type handlers for string parameters - #2221
Open
FirmaSpring wants to merge 1 commit into
Open
Preserve Size set by type handlers for string parameters#2221FirmaSpring wants to merge 1 commit into
FirmaSpring wants to merge 1 commit into
Conversation
When an anonymous object parameter goes through the IL generator path, the generated code set the parameter Size after invoking the registered type handler's SetValue, overwriting whatever Size the handler had configured (typically resetting it to 4000 or -1). Move the string Size emission into the non-handler branch so the handler owns the parameter configuration, matching what DynamicParameters already does. Fixes DapperLib#2141 Co-authored-by: FirmamentalSpring <287222957+FirmaSpring@users.noreply.github.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.
Problem
When a
TypeHandleris registered forstringand a query is executed with an anonymous object parameter (the IL generator path inCreateParamInfoGenerator), the generated code invokes the handler'sSetValueand then unconditionally sets the parameter'sSizebased on the string length heuristics (DbString.DefaultLength/-1), overwriting whateverSizethe handler configured.Reported in #2141. The
DynamicParameterspath already leaves the Size to the handler; only the IL path diverges.Reproduction
Fix
Move the string
Sizeemission into thehandler is nullbranch, so when a type handler is registered it fully owns parameter configuration, consistent with theDynamicParametersbehavior.Testing
Added
TypeHandlerSetValue_StringParameterSizeIsNotOverwritten_Issue2141toSqliteTypeHandlerTests(in-memory SQLite, no external database required). Verified it fails on current main and passes with this change; the existingSqliteTypeHandlerTestssuite passes.Fixes #2141