?
Solved

linq where OR syntax?

Posted on 2011-02-23
7
Medium Priority
?
728 Views
Last Modified: 2012-05-11
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
Comment
Question by:websss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Author Comment

by:websss
ID: 34967573
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
 
LVL 9

Expert Comment

by:s_chilkury
ID: 34967586
Try following:
WHERE ID == 1 || ID == 2 || ID == 3
0
 

Author Comment

by:websss
ID: 34967604
s_chilkury
can you match your example wth my code please with the for loop
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 34967609
you can try like this
Where ID in (1,2,3)
0
 

Accepted Solution

by:
websss earned 0 total points
ID: 34967932
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
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 35913564
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question