Foreach loop problem for Iqueyable object

Posted by Vikas on Stack Overflow See other posts from Stack Overflow or by Vikas
Published on 2010-06-03T05:49:30Z Indexed on 2010/06/03 5:54 UTC
Read the original article Hit count: 166

Filed under:
|

Hi,

Can we use foreach loop for Iqueryable object?

I'd like to do something as follow:

query = Iqueryable<Myclass> = objDataContext.Myclass; // objDataContext is an object of LINQ datacontext class

int[] arr1 = new int[] { 3, 4, 5 };

foreach (int i in arr1)
{
query = query.Where(q => (q.f_id1 == i || q.f_id2 == i || q.f_id3 == i));
}

It gives me wrong output as each time value if i is changed.

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-sql