bafilker
bafilker

Reputation: 209

Linq query 'and' 'or' operators

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?

Upvotes: 17

Views: 97642

Answers (3)

John Woo
John Woo

Reputation: 263693

Group your conditions by adding parentheses:

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

Upvotes: 9

Pranay Rana
Pranay Rana

Reputation: 176896

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'))

Upvotes: 48

AD.Net
AD.Net

Reputation: 13399

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.

Upvotes: 4

Related Questions