我正在使用Dapper针对DB2数据库(带有ODBC驱动器)做出Select语句。当我包含一个“ WHERE IN”子句时,它可以正常工作:
//Works!
var p = new DynamicParameters();
var list = new float[] { 0.35f, 0.36f, 0.37f };
p.Add("ids", list);
string query = $"select * from {_table} where FIELD1 in ?ids?";
return WithConnection(c => c.Query<Entity>(query, p));
但是,如果我包含另一个WHERE IN子句,则不会得到预期的结果:
//Unexpected result (I should get 2 elements but returns empty)
var p = new DynamicParameters();
var list = new float[] { 0.35f, 0.36f, 0.37f };
var list2 = new int[] { 2423634, 2423635, 2423636, 2423637, 2417456 };
p.Add("ids", list);
p.Add("ids2", list2);
string query = $"select * from {_table} where FIELD1 in ?ids? and FIELD2 in ?ids2?";
return WithConnection(c => c.Query<Entity>(query, p));
此外,如果我使用WHERE IN子句和简单条件,则会收到错误消息:
//Error Error: [SQL0302] Data conversion or data mapping error.
// Cause . . . . . : Error type 6 has occurred. Error types and
// their meanings are: ... 6 -- Numeric data that is not valid. ...
var p = new DynamicParameters();
var list = new float[] { 0.35f, 0.36f, 0.37f };
int id = 2423634;
p.Add("ids", list);
p.Add("id", id);
string query = $"select * from {_table} where FIELD1 in ?ids? and FIELD2 = ?id?";
return WithConnection(c => c.Query<Entity>(query, p));
如果我在没有WHERE IN的情况下使用该条件,则它会正常工作。
我做错什么了吗,或者可能是Dapper中的错误? (我认为使用1.50.2版本中解决的WHERE IN子句时也会出现类似的错误。)
谢谢。