[英]Simple list of string from Dapper Query
Is there any way to get a simple list of strings from a Dapper Query? 有什么方法可以从Dapper查询中获取简单的字符串列表吗? I don't want to create an object that contains all my field names by type.
我不想创建一个按类型包含我所有字段名称的对象。 My query returns one row of data.
我的查询返回一行数据。 Sometimes with 2 columns other times with 5 or 20 or 100 and I just want all the values returned as a single list of strings.
有时有2列,其他时候有5或20或100,而我只想将所有值作为单个字符串列表返回。
Dapper would make it easy to work with multiple rows, single column, via db.Query<string>(...)
. Dapper可以通过
db.Query<string>(...)
轻松处理多行,单列。
For multiple columns single row, you could try: 对于多列单行,您可以尝试:
var x = db.QuerySingle<(string,string)>(...)
(for two columns; add more items to the tuple for more) (对于两列;将更多项目添加到元组以获取更多信息)
This uses the value-tuple approach to read the data column-wise. 这使用值元组方法逐列读取数据。
However, this is only good for a handful of columns. 但是,这仅对少数列有用。 If you have hundreds of columns and a single row then I suggest transposing your query (perhaps via
PIVOT
). 如果您有数百列和一行,那么我建议转置您的查询(也许通过
PIVOT
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.