Solved

linq where OR syntax?

Posted on 2011-02-23
7
727 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
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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