linq where OR syntax?


I have the following code

however, every time it looks through it constructs the SQL to be

where ID =1 and ID= 2 and ID =3 ....
however, i need it to be OR:
where ID =1 OR ID= 2 OR ID =3 ....

how would i do this?

if (recordId.Length > 0)

                    string[] csv = recordId.Split(new char[] { ',' });

                    foreach (string row in csv)
                        query = query.Where(s => s.MasterProductID == Convert.ToInt32(row));

                { query = query.Where(s => s.MasterProductID == 0); }

Open in new window

Who is Participating?
websssConnect With a Mentor Author Commented:
The answer i was looking for was:

  string[] csv = recordId.Split(',');

                var query = from p in dataContext.MTSubProducts
                                 where csv.Contains(Convert.ToString(p.MasterProductID))
                                 select p;
websssAuthor Commented:
Actually, just realised its not even building the where clause
its simply overwritting it

how do i get it to build a multiple where clause and also use OR keyword

Try following:
WHERE ID == 1 || ID == 2 || ID == 3
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

websssAuthor Commented:
can you match your example wth my code please with the for loop
Pratima PharandeCommented:
you can try like this
Where ID in (1,2,3)
Amandeep Singh BhullarCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.