精致和条件

Tim*_*ott 9 sqlexception dapper

使用Dapper,以下抛出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 });
Run Code Online (Sandbox Code Playgroud)

嗯,SQL没有逗号.它必须与参数有关. OriginZip并且DestZipvarchar(10). zipsIEnumerable<int>.我尝试使用zips作为参数而不转换为字符串.同样的错误.

看起来非常简单.我究竟做错了什么?

Sam*_*ron 9

尝试:

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 });
Run Code Online (Sandbox Code Playgroud)