Reputation: 209
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
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
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
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