multi.Read()
.Select(x => new KeyValuePair<string, double>((string) x.URL, (double) x.MinsAgo)
.ToList();
Specify field names when mapping List<KeyValuePair> in Dapper
Pregunta
I have been getting results out of Dapper as a Dictionary:
using (var multi = cnn.QueryMultiple("dbo.[s_Dashboard_stats]",
commandType: CommandType.StoredProcedure))
{
var recentHits =
multi.Read().ToDictionary(x => (string)x.URL, x => (double)x.MinsAgo);
}
This was working fine but a change in the data has led (correctly) to duplicate key values. To get around this I thought I'd change the dictionary to a List instead:
var PopularHits =
multi.Read<KeyValuePair<string, double>>().ToList<KeyValuePair<string, double>>();
The list ends up with items but the values of the KVP are null, how do I project the values into the KeyValuePair objects? I can't seem to get the lambda syntax correct.....
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow