Dapper and In Condition

Using Dapper, the following throws are Incorrect syntax near ',' .

 const string sql = "select * from ZipToZipDistance z where z.NoRouteFound = 0" + " and z.OriginZip in (@zips) or z.DestZip in (@zips)"; var zipStrings = zips.Select(x => x.ToString()).ToArray(); var result = connection.Query<ZipToZipDistance>(sql, new { zips = zipStrings }); 

Hmm, SQL has no commas. It should have something to do with the parameter. OriginZip and DestZip are varchar(10) . zips IEnumerable<int> . I tried using zips as a parameter without converting to strings. The same error.

It seems very simple. What am I doing wrong?

+7
source share
1 answer

try:

 const string sql = const string sql = "select * from ZipToZipDistance z where z.NoRouteFound = 0" + " and z.OriginZip in @zips or z.DestZip in @zips"; var zipStrings = zips.Select(x => x.ToString()); var result = connection.Query<ZipToZipDistance>(sql, new { zips = zipStrings }); 
+7
source

All Articles