Is it possible to include a clause in the where (LINQ) but only if its “NOT” empty ?
i.e.
where c.Code == sCode && p.Code == code
In this case the variable (standard c#) is called code … if its NOT empty then the above where is great.. but if its empty then i don’t want to include in it the where
i.e.
where c.Code == sCode
In SQL its done like this
AND ( ( @code = '' )
OR ( @code <> ''
AND C.Code = @code
)
That’s for standard LINQ, I have no idea if it works for LINQ to SQL.
Edit:
This works through short circuit evaluation
if
c.Code == sCodeis false, it stops evaluating and returns falseotherwise, if
string.IsNullOrEmpty(code)is true, it stops evaluating and returns trueotherwise, return
p.Code == code