在Dapper </keyvaluepair>中映射List <keyvaluepair>时指定字段名称

时间:2013-12-06 11:52:33

标签: c# dapper

我已经将Dapper的结果作为词典获得结果:

  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);
  }

这工作正常,但数据的更改导致(正确)重复键值。为了解决这个问题,我想我会将字典更改为List:

var PopularHits =
    multi.Read<KeyValuePair<string, double>>().ToList<KeyValuePair<string, double>>();

列表以项目结尾,但KVP的值为null,如何将值投影到KeyValuePair对象中?我似乎无法使lambda语法正确.....

1 个答案:

答案 0 :(得分:2)

multi.Read()
    .Select(x => new KeyValuePair<string, double>((string) x.URL, (double) x.MinsAgo)
    .ToList();