Starting with the following LINQ query:
from a in things where a.Id == b.Id && a.Name == b.Name && a.Value1 == b.Value1 && a.Value2 == b.Value2 && a.Value3 == b.Value3 select a;
How can I remove (at runtime) one or more of the conditions in the where clause in order to obtain queries similar to the following ones:
from a in things where a.Id == b.Id && a.Name == b.Name && a.Value2 == b.Value2 && a.Value3 == b.Value3 select a;
Or
from a in things where a.Name == b.Name && a.Value3 == b.Value3 select a;
Rather than try to change existing where clauses, I’d refactor it to this:
That then becomes:
Now it should be reasonably clear how to proceed – conditionalise the calls to Where: