Reputation: 10236
I have a dictionary for which I want to retrieve results matching to those of list
here is what I have done so far
Dictionary<string, Dictionary<string, int>> SomeDictionary = new Dictionary<string, Dictionary<string, int>>();
List<int> MyList = new List<int>()
{
2,3,4,5
};
Dictionary<string, int> internalDictionary = new Dictionary<string, int>();
internalDictionary.Add("two", 2);
internalDictionary.Add("three", 3);
internalDictionary.Add("four", 4);
internalDictionary.Add("five", 5);
Dictionary<string, int> AnotherDictionary = new Dictionary<string, int>();
AnotherDictionary.Add("six", 6);
AnotherDictionary.Add("three", 3);
AnotherDictionary.Add("seven", 7);
SomeDictionary.Add("Dictionary1", internalDictionary);
SomeDictionary.Add("Dictionary2", AnotherDictionary);
var res = from l in MyList
select(from q in
(from p in
(from s in SomeDictionary
select s)
select p) where q.Value.Equals(l) select q);
The value returned is null. what am i Missing ?
I need matching KeyValuePair
where value matches internal dictionary values.
Upvotes: 0
Views: 2471
Reputation: 1024
Explanation:
So created inner join query with string and integer value after converting integer to string. Refer screencast that might be required output
Screen cast showing working code
This Linq snippet may be helpful:
var allinone = (from l in MyList
join d in SomeDictionary.SelectMany(s => s.Value) on l equals d.Value
select d);
Upvotes: 3
Reputation: 117029
Try this:
var res = from l in MyList
from q in SomeDictionary
from w in q.Value
where w.Value == l
select w;
I get this:
Upvotes: 1