我正在尝试运行以下查询但出现错误。
conn.Query("select d.ID, d.CategoryID from Document d inner join @Cases c on d.CaseID = c.ID", new { Cases = new List<string> { "000-6575-101", "5902-205" }});
当我运行命令时,我收到 Incorrect syntax near ','.
我的问题是,是否有可能像我正在做的那样做?
请您参考如下方法:
Dapper 支持 in这种情况的语法:
var ids = new List<string> { "000-6575-101", "5902-205" };
conn.Query("select d.ID, d.CategoryID from Document d where d.CaseID in @ids", new { ids});
这是 dapper 实际上会更改您的查询以执行您想要的操作(同时保持完全参数化等)的少数情况之一。
它还支持(可选,参见 SqlMapper.Settings ):
- 参数填充以减少查询计划缓存饱和度
- 使用
string_split在 SQL 2016 上用于整数类型(List<int>等)
