sql - How to query ODBC with Dapper with multiple parameters including a WHERE IN?
问题描述
I've hit an issue using Dapper to query an ODBC provider. The query in question is supplied several parameters. One of the parameters is used to populate a WHERE IN operator.
So far I've tried supplying the query with: DynamicParameters
, ?
regular parameters, ?name?
pseudo-positional parameters and some combinations of these.
SELECT companyId
,projectId
,contractId
,status
FROM certificate
WHERE companyId = ?companyId?
AND projectId = ?projectId?
AND contractId = ?contractId?
AND invoiceId IN ?invoiceIds?
var results = await connection
.QueryAsync<Certificate>(query, new { companyId, projectId, contractId, invoiceIds = new string[] { '1a', '1b', '2a' }});
Expected results are several rows being returned. If I hardcode the query with it's parameters it works fine, so the data I'm supplying should return rows.
Instead I'm getting an exception with the following message:
ERROR [07001] [DataDirect][ODBC Progress OpenEdge Wire Protocol driver]Value has not been specified for parameter 4.
ERROR [07001] [DataDirect][ODBC Progress OpenEdge Wire Protocol driver]Value has not been specified for parameter 5.
解决方案
如果那是您的代码,那么您的代码将无法编译。您没有为前三个参数提供任何值,并且在第四个参数中提供了非法字符而不是字符串。我看不出为什么这不起作用:
var results = await connection
.QueryAsync<Certificate>(query,
new { companyId=1, projectId=1, contractId=1, invoiceIds = new [] { "1a", "1b", "2a" }});
推荐阅读
- api - bitbucket 注释中缺少状态更改
- wordpress - 将 www 重定向到无 www
- excel - 使用特定工作簿时关闭 Excel 的 VBA 脚本
- sql - SQL:在已分组的 TABLE 上使用 CASE
- c# - 如何从 Asp.Net MVC 中的视图填充模型
- java - Java 并发实践“清单 15.7。Michael-Scott 非阻塞队列算法中的插入(Michael 和 Scott,1996 年)。”
- laravel - 如何使工作 laravel,vue session csrf
- javascript - 当猫鼬模型模式文件中需要函数时,Mongoose.model('model_name') 返回空对象
- python - Flask restful 和 flask jwt - 如何一起使用?
- html - 使用 flex 和 line-height+vh 时如何对齐尺寸?