Corrupt parameter replacements for lists, when one fieldname contains another · Issue #192 · DapperLib/Dapper · GitHub
Skip to content

Corrupt parameter replacements for lists, when one fieldname contains another #192

Description

@devblah

Hi guys,

I found an error for listed parameters:

First create a table like this:

CREATE TABLE DapperTest (
    Field INT PRIMARY KEY IDENTITY,
    Field_1 INT
);

Now use the following Query:

IEnumerable<dynamic> result = con.Query(
    "SELECT * FROM dbo.DapperTest WHERE Field IN @Field AND Field_1 IN @Field_1",
    new { Field = new[] { 1, 2 }, Field_1 = new[] { 2, 3 } });

You get the following exception:

{"Incorrect syntax near '_1'."}

Grabbed from SQL Profiler:

exec sp_executesql N'SELECT * FROM dbo.DapperTest WHERE Field IN (@Field1,@Field2) AND Field_1 IN (@Field1,@Field2)_1',N'@Field1 int,@Field2 int,@Field_11 int,@Field_12 int',@Field1=1,@Field2=2,@Field_11=2,@Field_12=3

As you can see Dapper renames all "@field" occurences regardless if the string ends there.

I had the same issue in my own SqlBuilder library and I replaced the exact string replacement with a replacement of the position and length given by System.Text.RegularExpressions.Match class. Maybe that helps.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions