Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
So if I write a statement like

<br />var results = from items in collection<br />                     where from.SomeProperty == SomeValueDefinedEarlier<br />                     where from.SomeOtherProperty == SomeOtherValueDefinedEarlier<br />


Then the 2 where statements are an AND. How can an OR be done. Bellow is not what I expect the code to be, but gives a clear idea (I think) of why and what I am wanting to do.

<br />var results = from items in collection<br />                     where from.SomeProperty == SomeValueDefinedEarlier<br />                     where from.SomeOtherProperty == SomeOtherValueDefinedEarlier<br />                     OR<br />                     where from.SomeProperty == SomeValueDefinedEarlier2<br />                     where from.SomeOtherProperty == SomeOtherValueDefinedEarlier2<br /><br />


Thank you,
Posted

1 solution

You can use boolean operators, like the && operator instead of the two 'where' clauses, and the | operator for an OR operation. For example, your first example would be:
<br />var results = from items in collection<br />                     where from.SomeProperty == SomeValueDefinedEarlier<br />                     && from.SomeOtherProperty == SomeOtherValueDefinedEarlier<br />

Second example would be something like this:
<br />var results = from items in collection<br />                     where ((from.SomeProperty == SomeValueDefinedEarlier)<br />                     && (from.SomeOtherProperty == SomeOtherValueDefinedEarlier))<br />                     || ((from.SomeProperty == SomeValueDefinedEarlier2)<br />                     && (from.SomeOtherProperty == SomeOtherValueDefinedEarlier2))<br />


modified on Tuesday, May 26, 2009 6:25 AM
 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900