Frage

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.....

War es hilfreich?

Lösung

multi.Read()
    .Select(x => new KeyValuePair<string, double>((string) x.URL, (double) x.MinsAgo)
    .ToList();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top