Reputation: 103
I have a nested dictionary from which I want to derive a Lookup. Example data of the dictionary is following:
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}});
This LINQ statement is working:
var cols = from a in binary_transaction_model
from b in a.Value
where b.Value == true
group a.Key by b.Key;
It gives me an IEnumerable<IGrouping<String,String>>
. For lookup purposes I need this result as a Lookup data structure. How can I do this? How should a ToLookup()
signature look like? (Edit: I want to have a Lookup<String,String>
.)
Upvotes: 0
Views: 475
Reputation: 57210
This should work:
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);
Upvotes: 2