17

使用 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 });

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

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

4

1 回答 1

15

尝试:

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 });
于 2012-04-20T14:21:04.943 回答