Reputation: 10604
I was wondering if there is an easy way to place two Lambda expressions in a single (Linq/Where) query?
For example, I currently call a method with something like the following:
string testing = "blablabla";
if(testing == "" || testing == null)
I have tried a few combinations such as:
testing.Where(x => x == ("") || x=> x == null);
But the above doesn't work. I know I can set up a method that returns a predicate/bool, but, at the moment, I am interested in Lambdas and was just wondering how to achieve this.
Do I need to chain multiple Where methods, or is there a way to achieve multiple Lambdas?
(p.s. I know about IsNullOrEmpty, this is just the first example I could think of!)
Upvotes: 0
Views: 962
Reputation: 6593
If you're looking for a general way to combine query conditions in arbitrary ways, you can use expression trees:
http://msdn.microsoft.com/en-us/library/bb882637.aspx
Upvotes: 0
Reputation: 108957
You can always combine them to a single lambda.
testing.Where(x => x == null || x == ("") );
Upvotes: 7