I have a table structure like this:
Table tbUser
--ID (int)
--Name (varchar)
--Birthday (datetime)
--Rating (double)
When
"SELECT * FROM tbUser"
I want each row in query result looks like (turns every column into string format):
row["ID"] = "1";
row["Name"] "John"
row["Birthday"] = "1980-01-01"
row["rating"] = "3.4"
The reason I need strings as result is they are easy to manipulate/format/display and some times safer (If another engineer changed column type in DB --e.g. "rating" column changed from double
to int
, the program is less likely throw exception as it only cares about strings)
I know there's a way to convert a DapperRow to IDictionary<string, object>
, which is very close to IDictionary<string, string>
;
var result = conn.Query("SELECT * FROM tbUser");
foreach (IDictionary<string, object> row in result) {
// I have to write my own object->string conversion in every loop
}
Any suggestion is highly appreciated!