My LINQ query returns values if “attribute” is bigger than 0 else it doesn’t work and I get no error.
I guess the && in the third line wants another statement which it doesn’t get if “attribute” isn’t bigger than 0. How can I get over this?
Edit: The code I’ve written first, was doing what abatishchev’s answer is saying. I’ve tried to do a shorthand if statement without else but I’ve read about that wrong, so the code was meant to do something else then it actualy did. Thank you for the enlightenment on that matter but I still don’t know how to implement my initial wish to linq, so I’ve rearranged the code to something that is nearer to my goal.
int attribute = 0;
var query = from x in db.Table1
where x.ValueId == 1
if(attribute > 0)
x.Table2.Attribute == attribute
select x;
If attribute is bigger than 0, then I wan’t to add an additional where clause to my query.
Thank you for your help.
1 Answer