0

我有一个嵌套字典,我想从中派生一个查找。字典的示例数据如下:

var binary_transaction_model = new Dictionary<string, Dictionary<string, bool>>();
binary_transaction_model.Add("123", new Dictionary<string, bool>(){{"829L", false},{"830L", true}});
binary_transaction_model.Add("456", new Dictionary<string, bool>(){{"829L", true},{"830L", false}});
binary_transaction_model.Add("789", new Dictionary<string, bool>(){{"829L", true},{"830L", true}});

此 LINQ 语句正在工作:

var cols = from a in binary_transaction_model
    from b in a.Value
    where b.Value == true
    group a.Key by b.Key;

它给了我一个IEnumerable<IGrouping<String,String>>. 出于查找目的,我需要将此结果作为查找数据结构。我怎样才能做到这一点?签名应该是ToLookup()什么样子的?(编辑:我想要一个Lookup<String,String>

4

1 回答 1

2

这应该有效:

var cols = (from a in binary_transaction_model
            from b in a.Value
            where b.Value == true
            select new { aKey = a.Key, bKey = b.Key })
            .ToLookup(x => x.bKey, x => x.aKey);
于 2013-05-13T15:41:28.130 回答