SELECT * FROM X WHERE id IN (...) with Dapper ORM

問題:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章