多条件查询
“the car is red and costs less than $10”:
Expression<Func<Car, bool>> theCarIsRed = c => c.Color == "Red";
Expression<Func<Car, bool>> theCarIsCheap = c => c.Price < 10.0;
IQueryable<Car> carQuery = …;
var query = carQuery.Where(theCarIsRed).Where(theCarIsCheap);
“the car is red or the car costs less than $10”
To combine lambda expressions, I can write:
Expression<Func<Car, bool>> theCarIsRed = c => c.Color == "Red";
Expression<Func<Car, bool>> theCarIsCheap = c => c.Price < 10.0;
Expression<Func<Car, bool>> theCarIsRedOrCheap = theCarIsRed.Or(theCarIsCheap);
var query = carQuery.Where(theCarIsRedOrCheap);
浙公网安备 33010602011771号