The problem you are facing is delayed execution, you should be able to find a lot of information about it, but basically none of them are executed until you actually try to read the data from IQueryable (convert it to IEnumerable or List or other similar operations). This means that all this happens after the completion of foreach, when I am set to the final value.
, , for :
foreach (int i in arr1)
{
int tmp = i;
query = query.Where(q => (q.f_id1 == tmp || q.f_id2 == tmp || q.f_id3 == tmp));
}
, , IQueryable.