我想做类似下面的事情,其中 ls 是一对(id 和值匹配 blah)。也许如果我可以获得列表匹配的索引,我可以正常使用列表并在代码中获取 id
select @id from table1 where blah in @ls
最佳答案
Dapper 是 SQL 的一个非常薄的饰面。它作为语法更改添加的唯一内容是IN
扩展:
x in @foo
至
x in (@foo0, @foo1, @foo2, @foo3)
但是,我认为您的查询不能这样写。那么,第一步就是用常规 SQL 编写查询。如果这是 SQL-Server,我会想:
- 将分隔字符串输入转换为表格输出的 UDF
- 内部联接
例如:
select #x.id
from dbo.MyMagicUdf(@s) #x -- has columns id and value
inner join table1 t on t.blah = #x.value -- or whatever the join is
但要重复一遍:第一步是用 SQL 为您的 RDBMS 编写它。一旦您可以使用它,就可以轻而易举地使用它。
关于.net - 在mysql中获取索引还是使用配对列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12821148/