Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

Literal replacements causing DAP214

Open bsagal opened this issue 3 months ago • 0 comments

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

bsagal avatar Sep 28 '25 15:09 bsagal