Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq query 'and' 'or' operators

Tags:

c#

.net

linq

I have written a LINQ query with 'or' condition and 'and' but its not working well.

from x in db.fotoes.Where(x => x.uid == NewsId && 
x.ukat == 'fukat1' || x.ukat == 'fukat2')

i cant figure out why its not working,can anybody help me to fix this problem?

like image 622
bafilker Avatar asked Jan 13 '13 12:01

bafilker


3 Answers

Just try like this, you need to use parentheses to group your conditions:

from x in db.fotoes.Where(x => x.uid == NewsId && 
(x.ukat == 'fukat1' || x.ukat == 'fukat2'))
like image 120
Pranay Rana Avatar answered Nov 17 '22 07:11

Pranay Rana


Group your conditions by adding parentheses:

from x in db.fotoes.Where(x => (x.uid == NewsId) && 
                         (x.ukat == 'fukat1' || x.ukat == 'fukat2'))
like image 9
John Woo Avatar answered Nov 17 '22 05:11

John Woo


from x in db.fotoes.Where(x => x.uid == NewsId && (
x.ukat == 'fukat1' || x.ukat == 'fukat2'))

Is it what you're trying to do? You can group a set of conditions by having them inside parenthesis.

like image 4
AD.Net Avatar answered Nov 17 '22 05:11

AD.Net