I am using Dapper in the project, and it's ok if I need to get either the single primitive type (int, decimal, string, etc) or any db entity, but I need to read just 2 columns from the table, and I faced with lots of the challenges here:
This is a simple query:
SELECT col1, col2 FROM Table1
Where I expect to receive string and int
And this is how I read the data once the query is implemented:
var field1 = (await result.ReadAsync<string, int>()).FirstOrDefault();
And this is not compilable. I tried to create the class which contains 2 fields: string and int and use that type instead of . So it results to the following correction:
var field1 = (await result.ReadAsync<MyData>()).FirstOrDefault();
class MyData
{
string...
int ...
}
and it compiles but I get null for string and the proper data for int.
The query itself is correct, I tested it and it's fine. So the question is how to read the 2 columns?