Im trying to convert a dynamic query from dapper to IDictionary
const string sql = @"SELECT Name, Street FROM Contact";
dynamic query = null;
using (var cn = Connection)
{
query = cn.Query<dynamic>(sql);
}
var rows = query as IDictionary<string, object>;
foreach (var row in rows)
{
// Getting values and objects
}
But the cast always return null. Any clue?
You need to cast the individual rows as IDictionary<string, object>
:
const string sql = @"SELECT Name, Street FROM Contact";
IEnumerable<dynamic> results = null;
using (var cn = Connection)
{
results = cn.Query<dynamic>(sql);
}
foreach (var row in results)
{
var fields = row as IDictionary<string, object>;
// do something with fields["Name"] and fields["Street"]
}
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