Skip to content

Match constructors for nullable reader field types - #2284

Open
tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/nullable-reader-field-types
Open

tuncaypeker wants to merge 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/nullable-reader-field-types

Conversation

@tuncaypeker

Copy link
Copy Markdown
Contributor

Fixes #1498.

A reader that reports DateTime? from GetFieldType cannot materialize a class with a matching DateTime? constructor parameter. DefaultTypeMap unwraps the parameter to DateTime but compares it against the reported DateTime?, rejecting the constructor and reporting that no matching constructor exists.

Unwrap the reported column type as well during constructor comparison. Existing emitted conversions already handle the boxed underlying value and DBNull, so no deserializer IL changes are needed. Preserve the existing name checks, strict type matching, enum/char special cases, and registered-handler behavior.

Validation:

  • Reproduced on unmodified upstream main b5e17f9 on net10.0 through GetRowParser and a database-free DbDataReader reporting the exact nullable schema. Of the initial 29 cases, six fail during constructor selection and 23 controls pass. The same 29 cases all pass after the fix.
  • The final 39 cases cover DateTime and integer values, DBNull, nullable/non-nullable field metadata, constructor/property/struct mapping, nullable and non-nullable Guid and enum targets, char, registered handlers, and rejection of incompatible constructor names/types.
  • The new cases plus existing ConstructorTests, TypeHandlerTests, EnumTests, TypeMappingRegressionTests, DataReaderTests, NullTests, and SQLite tests pass on net481 (170 passed), net8.0 (173 passed), and net10.0 (173 passed), with no failures or skips. All 39 new cases pass on each framework.
  • No actual DBF file or DbfDataReader integration run was performed. The fake reader supplies the reported field types and boxed values directly; existing SQL Server integration checks use SQL Server 2025 LocalDB with both SqlClient providers.
  • 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.

Should DbDataReader implementations be supported that return System.Nullable<X> from GetFieldType?

1 participant