Skip to content

DynamicParameters DbType Mapping Issues in Parameterized Queries #2157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zwyl2001 opened this issue Apr 11, 2025 · 0 comments
Open

DynamicParameters DbType Mapping Issues in Parameterized Queries #2157

zwyl2001 opened this issue Apr 11, 2025 · 0 comments

Comments

@zwyl2001
Copy link

‌Parameter Type Mapping Precision Issue in Dapper Parameterized Queries‌
When using Dapper for parameterized queries, automatically inferred database parameter types based on the parameter value's DbType may lack precision. For example:

DbType.AnsiString is mapped to NpgsqlDbType.Text in PostgreSQL/Npgsql.
This imprecise mapping can lead to inefficient query execution plans, resulting in ‌prolonged query times‌ and degraded performance (e.g., due to implicit type conversions or index mismatches).

‌Proposed Solution‌
To address this, we recommend extending Dapper to allow ‌explicit configuration of parameter types‌ before SQL execution via DbCommand. This could be achieved by:

Introducing an extensibility mechanism (e.g., injected extension objects) to override parameter mappings where necessary.
Enforcing precise database-specific types (e.g., NpgsqlDbType.Citext, NpgsqlDbType.Jsonb) instead of relying on generic DbType defaults.

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

No branches or pull requests

1 participant