问题:
What is the best way to write a query with IN clause using Dapper ORM when the list of values for the IN clause is coming from business logic?当 IN 子句的值列表来自业务逻辑时,使用 Dapper ORM 编写带有 IN 子句的查询的最佳方法是什么? For example let's say I have a query:例如,假设我有一个查询:
SELECT *
FROM SomeTable
WHERE id IN (commaSeparatedListOfIDs)
The commaSeparatedListOfIDs
is being passed in from business logic and it can be any type of IEnumerable(of Integer)
.这个commaSeparatedListOfIDs
是从业务逻辑传入的,它可以是任何类型的IEnumerable(of Integer)
。 How would I construct a query in this case?在这种情况下,我将如何构建查询? Do I have to do what I've been doing so far which is basically string concatenation or is there some sort of advanced parameter mapping technique that I'm not aware of?我是否必须做到目前为止我一直在做的基本上是字符串连接的工作,或者是否有某种我不知道的高级参数映射技术?
解决方案:
参考一: https://en.stackoom.com/question/ZC7p参考二: https://stackoom.com/question/ZC7p