To do what you want, I would use the Linq ToLookup method to create an ILookup instead of using a dictionary. ToLookup was specifically created for this type of script. This is basically an indexed group search. You want to group your cars with Code .
var carCodeLookup = cars.ToLookup(car => car.Code);
Creating a carCodeLookup will be slow, but you can use it to quickly find Code based cars. To get a list of cars that are in the list of regular codes, you can quickly browse.
var filteredCarsQuery = commonCodes.SelectMany(code => carCodeLookup[code]);
This assumes that your car list does not change very often, and your common codes are dynamic between requests.
DRBlaise
source share