We are trying to use Dapper to get a list of records from a SQL database with the following snippet of code:
var result = await conn.QueryAsync<KeyValuePair<string,string>>("Select Tag, Description from Tags");
The result is all the rows from the table, however, both the Tag and the Description are all null.
Dapper needs to know that the Tag and Description columns should map to the Key and Value properties.
The simplest way to do this is to specify the column aliases directly in the SQL query:
var result = await conn.QueryAsync<KeyValuePair<string, string>>(
"Select Tag [Key], Description [Value] from Tags");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With