5

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.

0

1 Answer 1

3

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).

Sign up to request clarification or add additional context in comments.

1 Comment

Need to add System.ValueTuple nuget package to use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.