我已经将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语法正确.....
答案 0 :(得分:2)
multi.Read()
.Select(x => new KeyValuePair<string, double>((string) x.URL, (double) x.MinsAgo)
.ToList();