I am using Dapper to fetch a 2 column resultset into a dictionary. I noticed that intellisense shows me a .ToDictionary() when I hover over the resultset but I cannot get it to work since dapper uses dynamic properties/expandoObject
Dictionary<string, string > rowsFromTableDict = new Dictionary<string, string>();
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
var results = connection.Query
("SELECT col1 AS StudentID, col2 AS Studentname
FROM Student order by StudentID");
if (results != null)
{
//how to eliminate below foreach using results.ToDictionary()
//Note that this is results<dynamic, dynamic>
foreach (var row in results)
{
rowsFromTableDict.Add(row.StudentID, row.StudentName);
}
return rowsFromTableDict;
}
}
thank you