I have a List containing several keywords. I foreach through them building my linq query with them like so (boiled down to remove the code noise):
List
You're reusing the same variable (key
) in your lambda expression.
See my article on anonymous methods for more details, and there are a number of related SO questions too:
The simple fix is to copy the variable first:
List keys = FillKeys()
foreach (string key in keys){
string copy = key;
q = q.Where(c => c.Company.Name.Contains(copy));
}