Skip to content

Fix DAP037 false positive when the result type is an enum - #239

Open
SENESO wants to merge 9 commits into
DapperLib:mainfrom
SENESO:fix-dap037-enum-result
Open

SENESO wants to merge 9 commits into
DapperLib:mainfrom
SENESO:fix-dap037-enum-result

Conversation

@SENESO

@SENESO SENESO commented Nov 24, 2026

Copy link
Copy Markdown

Fixes #228

Root cause

Inspection.IdentifyDbType doesn't recognize enum types, so the analyzer treats Query<SomeEnum> as a user type with no settable members and reports DAP037 ("Type 'SomeEnum' has no settable fields or properties"). Suppressing the warning worked because the runtime already handles enums: CommandUtils.As<T> converts both numeric values and strings to the enum.

Fix

IdentifyDbType now maps an enum type to the DbType of its underlying type, without advertising a reader method (there is no DbDataReader.GetEnum). Consequences, all desired:

  • the analyzer no longer reports DAP037 for enum results (Query<SomeEnum>, Query<SomeEnum?>, ExecuteScalar<SomeEnum>, ...)
  • enum results are no longer flagged BindResultsByName (matches other scalar results like int)
  • the generator emits the inbuilt RowFactory<SomeEnum> (flexible conversion via CommandUtils.As) instead of a custom empty row factory

Enum members of user types and enum parameters are unchanged: no reader method is advertised for enum members (they still use GetFieldValue<T> + flexible fallback), and verified against the SqliteUsage interceptor snapshots.

Test plan

  • New DAP037.EnumResultTypesDoNotWarn verifier test (enum, nullable enum, long-backed enum, enum member) - fails before the fix, passes after
  • SqliteUsage interceptor scenario extended with Query<SomeEnum>; regenerated snapshots show RowFactory.Inbuilt.Value<SomeEnum>()
  • SqliteTests.SelectEnumValues executes the intercepted AOT path against in-memory SQLite and asserts the returned enum values
  • Full Dapper.AOT.Test run (net10.0): no regressions; only pre-existing Docker-dependent integration failures (Postgres/MsSql DateOnlyTimeOnly/BatchPostgresql)

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.

DAP037 error when return type is an enum

1 participant