DapperLib / DapperLib/Dapper

Literal replacements causing DAP214

Open
#2,181 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug
When using Literal replacement ({=XXX}) in a SQL query, Dapper AOT emits the following error:

Error DAP214 : Variable @XXX is not declared and no corresponding parameter exists (https://aot.dapperlib.dev/rules/DAP214)

This happens even though the parameter is correctly supplied in the parameters object.
If I change the query to use @XXX instead of {=XXX}, it works correctly.

To Reproduce

var result = await db.QueryAsync(
    "select Id, Name from Users where UserTypeId = {=Admin}",
    new { Admin = 123 });
  1. Compile with Dapper AOT enabled.
  2. Observe the error DAP214.

Expected behavior
Dapper should recognize Admin as a supplied parameter and generate code that binds it correctly when used with Literal replacement.

Actual behavior
Dapper reports DAP214 and refuses to compile, incorrectly stating that the parameter does not exist.

Additional context
TargetFramework = net9.0
Dapper Version = 2.1.66
Dapper.AOT Version = 1.0.48
Microsoft.Data.SqlClient Version = 6.1.1

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 reproducing the shown query with Dapper AOT enabled and the listed package versions. Trace how the Dapper AOT analyzer handles literal replacements and supplied parameters. Done means the example compiles without DAP214 and binds Admin correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.