Skip to content

Apply scalar conversions to unbuffered QueryAsync results - #2275

Open
tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/unbuffered-query-conversion
Open

tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/unbuffered-query-conversion

Conversation

@tuncaypeker

Copy link
Copy Markdown

Fixes #1901.

QueryAsync with CommandFlags.None casts each deserialized value directly to T, while the buffered and synchronous paths use GetValue. A query such as SELECT 1 therefore converts to bool when buffered but throws InvalidCastException when enumerated without buffering.

Pass the effective result type to the deferred reader and use the existing GetValue conversion. This also makes nullable and numeric conversions, and conversion-error diagnostics, consistent with the buffered path. The change is three production lines and adds no public API or dependencies.

Validation:

  • Four regression theories compare buffered and unbuffered behavior for integer-to-boolean conversion, nullable booleans, integer-to-Int64 conversion, and invalid-conversion diagnostics.
  • On the unmodified upstream code, all eight unbuffered cases fail and all eight buffered controls pass across Microsoft.Data.SqlClient and System.Data.SqlClient on net10.0 against SQL Server 2025 LocalDB.
  • After the fix, AsyncTests and QueryMultipleTests against SQL Server 2025 LocalDB pass on net481, net8.0, and net10.0: 170 passed and four performance tests skipped per framework, including all 16 new regression cases per framework.
  • 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.

@mgravell

Copy link
Copy Markdown
Member

You're on a mission! I'll need a moment to chew through all these, but: thanks for the input, appreciated.

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.

Cell value not converted when using QueryAsync<T> with CommandFlags.None

2 participants