SQL Server with Dapper
List<string> valueList = new List<string> { "20230626", "20230808"};
string sql = "SELECT * FROM MyTable WHERE @Values IS NULL OR Value IN @Values";
var result = connection.Query<dynamic>(sql, new { Values = valueList });
SqlException: an expression of non-boolean type specified in a context where a condition is expected, near ','
If I use this, then it works OK:
List<string> valueList = null
Without NULL check, it works OK
SELECT * FROM MyTable WHERE Value IN @Values
- Is Dapper rewriting the query when using IN parameter?
- Is there a workaround that does not use dynamic SQL or table-valued parameters or similar?