I use LINQ on a Dictionary<string, IList<ID>> like this:
var searchCategories = new List {"A", "B", "C"};
Result = CategoryMapper.Mapping.Where(
x => searchCategories.Contains(x.Key)).
Select(x => new Tuple<string, IList<ID>>(x.Key, x.Value)).ToList();
This returns all ids that are either in Category A, B or C. However what I would like to do is retrieve ids that are in Category A, B and C.
I’m having difficulties figuring out how to do this with Linq.
UPDATE
I’m sorry but I should have added some more information in my initial post. The lists in my dictionary look somewhat like this (I only use numbers here to make it simple):
A : {1, 2, 3}
B : {1,3}
C : {3}
So what I would like as a result of my query would be ‘3’ in this case because it is the only number that has all categories.
Looks like you’re just taking the intersection of all the lists. That should be simple to obtain.
If your
IDtype doesn’t implement theIEquatable<ID>interface, then you may need to provide an equality comparer (that I assume you have) to perform the comparisons.