• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 730
  • Last Modified:

linq where OR syntax?

Hi

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));
                    }

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

Open in new window

0
websss
Asked:
websss
1 Solution
 
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

thanks
0
 
s_chilkuryCommented:
Try following:
WHERE ID == 1 || ID == 2 || ID == 3
0
 
websssAuthor Commented:
s_chilkury
can you match your example wth my code please with the for loop
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Pratima PharandeCommented:
you can try like this
Where ID in (1,2,3)
0
 
websssAuthor 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;
0
 
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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now