Skip to content

Honor registered type handlers for matching scalar result types - #2281

Open
tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/scalar-type-handler-precedence
Open

tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/scalar-type-handler-precedence

Conversation

@tuncaypeker

Copy link
Copy Markdown
Contributor

Fixes #1218.

ExecuteScalar and ExecuteScalarAsync return a provider value directly when it already matches T, bypassing a registered type handler. For example, a DateTime handler that sets DateTimeKind.Utc runs during property mapping but is skipped by both scalar methods.

Consult registered non-enum handlers before the matching-type shortcut in Parse. Preserve null/DBNull handling and the existing PreferTypeHandlersForEnums behavior.

Validation:

  • Reproduced on unmodified upstream main at 64bdfa8 on net10.0: eight scalar regression cases fail with DateTimeKind.Unspecified instead of Utc. Property-mapping controls invoke the handler successfully; sixteen null/no-row and enum controls pass.
  • Added 24 test cases across System.Data.SqlClient and Microsoft.Data.SqlClient, covering sync/async scalar calls, nullable/non-nullable DateTime, null/no-row results, and enum handler opt-in.
  • Related type handler, enum, date/time, SQLite, and ExecuteScalar tests pass against SQL Server 2025 LocalDB: net481 has 108 passed and one existing Entity Framework test skipped; net8.0 and net10.0 each have 113 passed and no skips. No failures.
  • The full repository test suite was not run.
  • Release library build succeeds for net461, netstandard2.0, net8.0, and net10.0 with zero warnings or errors.

This branch has not been deployed

No deployments
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.

Bug: TypeHandler.Parse not called with Scalar* methods

1 participant