Dapper WHERE IN与Postgres的字符串语句

时间:2016-12-08 16:54:55

标签: c# postgresql dapper where-in

我看过Dapper WHERE IN statement with ODBC

但我不确定Dapper是否支持Postgres的WHERE IN(" String1"," String2")语法。这支持吗?我尝试挖掘代码,但我现在还没有时间。到目前为止,我只看过整数的例子。

示例:

_connection.QueryAsync<Lookup>("select * from lookup where lower(discriminator) in @types", new { types = new[] {"Prefix", "Suffix"} });

结果: PostgresException {&#34; 42601:语法错误在\&#34; $ 1 \&#34;&#34;}

说明:

{select * from lookup where lower(discriminator) in $1}

1 个答案:

答案 0 :(得分:3)

如果我没错,Postgres中的IN运算符不会支持数组作为参数。而不是IN尝试ANY运营商,如下所示:

var query = "SELECT * FROM lookup WHERE LOWER(discriminator) = ANY(@types)";

_connection.QueryAsync<Lookup>(query, new { types = new[] {"Prefix", "Suffix"} });