I have a LINQ expression that joins two tables. I want to conditionally check another boolean value: (notice text between ********* below)
bool status = testfunc();
var List =
from t in Houses
join k in Tbl_HouseOwner on t.HouseCode equals k.HouseCode
where k.ReqCode== t.ReqCode
*********** if (status) { where k.Name.Contains(Name) } **********
select new
{
...
name = k.Name,
...
};
You can use
statusto mask the condition, like this:If the
statusisfalse, the OR||will succeed immediately, and the AND&&will be true (assuming that we’ve got to evaluating the OR||, the left-hand side of the AND&&must have been true). If thestatusistrue, on the other hand, thek.Name.Contains(Name)would need to be evaluated in order to finish evaluating the condition.