Skip to content

Defer multi-map deserialization until the first row - #2286

Open
tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/empty-multimap-deserializer
Open

tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/empty-multimap-deserializer

Conversation

@tuncaypeker

Copy link
Copy Markdown
Contributor

Fixes #1275.

Multi-mapping builds deserializers before reading any rows. Providers such as SQLite can report different field types for empty results, so a query that maps successfully with rows can throw a missing-constructor exception when it returns nothing.

Read the first row before creating the deserializers in both generic and Type[] MultiMapImpl paths, and include that row in the mapping loop. Keep result draining and completion callbacks outside the row guard for owned queries. GridReader continues to control advancement and disposal for borrowed readers. No public APIs or dependencies are added.

Validation:

  • Reproduced on unmodified upstream main b5e17f9, net10.0, with real Microsoft.Data.Sqlite: four empty-result cases fail across sync/async buffered generic/Type[] overloads, while four populated controls pass.
  • Added 44 cases covering empty/single/multiple/empty/populated cache transitions; both generic and Type[] overloads; initially open/closed connections; GridReader empty/populated grids followed by another result; early disposal; and invalid splitOn names on populated results.
  • Both SqlClient providers cover sync/async, buffered/unbuffered multi-mapping, completion callbacks with no result set / empty result / one row, and SQL errors after an empty first result.
  • SQLite coverage includes sync buffered/unbuffered and async buffered calls. This patch leaves async wrapper command/reader ownership unchanged.
  • All 44 new cases and selected existing MultiMapTests, MultiMapCachePoisoningTests, QueryMultipleTests, AsyncTests, ProcedureTests, and SQLite tests pass on net481, net8.0, and net10.0: 401 passed / 12 skipped per framework, no failures. Skips are existing performance cases and the independently known Microsoft.Data.SqlClient pipelining issue Async Pipelined execution does not work with Microsoft.Data.SqlClient. #2028.
  • 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.

Dapper try to find Int32 parameters construtor when query returns no row

1 participant