You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Corrupt parameter replacements for lists, when one fieldname contains another #192
CREATETABLEDapperTest (
Field INTPRIMARY 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
mgravell commentedon Oct 14, 2014
Ouch! well that's a clear bug; my bad - will fix
mgravell commentedon Oct 14, 2014
Fix pushed to git (not yet deployed to nuget)