有人可以告诉我正确的查询方式:
dictionary of dictionary
Dictionary<int, Dictionary<Guid, AutoStopWatchAndLog>> _dicDictionaryThread
我正在寻找的是来自第一级的任何一级,然后来自第二级中任何级别小于x的项目
请注意:Dictionary<int, Dictionary<Guid, AutoStopWatchAndLog>>
var mostlikey = dics.FirstOrDefault(x=>x.Value.Where(y=>y.Value.Level > x));
答案 0 :(得分:0)
如果您想要将 new 字典词典过滤到所需的项目,则需要预测两个级别的词典,如下所示:
var query = _dicDictionaryThread.Select(o => new {o.Key, Value = o.Value
.Where(y=>y.Value.Level > x)
.ToDictionary(y => y.Key, y => y.Value)})
.Where(o => o.Value.Any())
.ToDictionary(o => o.Key, o => o.Value);
如果你能够轻松理解这一点并向其他人解释,那就去吧,否则只需使用传统的循环 - 你不会从Linq获得任何性能提升可能需要更长时间才能破译。