DapperLib / DapperLib/Dapper

DynamicParameters DbType Mapping Issues in Parameterized Queries

Open
#2,157 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

‌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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing DynamicParameters into DbCommand parameter creation, then compare the generic DbType path with the PostgreSQL/Npgsql mapping described here. Done would be a clearly specified extensibility mechanism that permits precise database-specific types without breaking existing parameterized queries; the issue does not name implementation files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, postgresql
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.