Skip to content

Select batch parameter readers by runtime type - #2278

Open
tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/mixed-batch-parameter-types
Open

tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/mixed-batch-parameter-types

Conversation

@tuncaypeker

Copy link
Copy Markdown

Fixes #1708.

Batch Execute and ExecuteAsync cache the first item's parameter reader for every item. If a sequence starts with a derived instance and later contains a base instance or a sibling subclass, binding the later item throws InvalidCastException.

Refresh the cached parameter reader when the runtime type changes, in sync, sequential async, and pipelined execution. Consecutive items of the same type keep reusing the current reader without another cache lookup. Command text restoration and parameter clearing retain their existing order. No public API or dependencies are added.

Validation:

  • Reproduced against SQL Server 2025 LocalDB on unmodified upstream main at 1880947: 12 mixed-type regressions fail and 12 controls pass on net10.0; eight Microsoft.Data.SqlClient pipelined cases are skipped for the independently reproduced Async Pipelined execution does not work with Microsoft.Data.SqlClient. #2028 issue.
  • Tests cover derived/base/derived, base/derived/base, sibling subclasses, and homogeneous derived sequences, through Execute and ExecuteAsync with and without pipelining. Both SqlClient providers are covered for ordinary execution. System.Data.SqlClient pipelined batches contain 105 items to exercise command recycling after MAX_PENDING (100).
  • After the fix, 24 cases pass on net10.0, with the same eight Async Pipelined execution does not work with Microsoft.Data.SqlClient. #2028 skips and no failures.
  • Microsoft.Data.SqlClient pipelined execution is not validated by this change; the existing EndExecuteNonQuery failure also occurs for homogeneous controls and is outside this fix.
  • Selected AsyncTests, ParameterTests, ProcedureTests, LiteralTests, and SQLite tests pass against SQL Server 2025 LocalDB on net481 (381 passed / 19 skipped), net8.0 (376 passed / 16 skipped), and net10.0 (376 passed / 16 skipped), with no failures. Each framework includes all 24 active new cases and eight Async Pipelined execution does not work with Microsoft.Data.SqlClient. #2028 skips; the remaining skips are existing disabled/performance and provider-specific tests.
  • 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.

Odd behaviour with Execute(Async) and typed IEnumerable<T>

1 participant