简体   繁体   中英

Simple list of string from Dapper Query

Is there any way to get a simple list of strings from a Dapper Query? 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.

Dapper would make it easy to work with multiple rows, single column, via 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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM