Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Literal replacements causing DAP214 #2181

@bsagal

Description

@bsagal

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions