In C# is there an elegant way to apply variance to a lambda expression? -


my application facilitates multi-criteria search using predicate builder. lets 1 of these criteria allows user specify how many bathrooms want in house.

i can use predicate builder , retrieve database houses have number of bedrooms equalling user specified:

predicate = predicate.and(x => x.numberofbathrooms == viewmodel.numberofbathrooms); 

say want return houses number of bathrooms +/- 1 user entered. if 2 entered, houses 1, 2 , 3 bathrooms applied.

is following way achieved?

predicate = predicate.and(x => x.numberofbathrooms == viewmodel.numberofbathrooms && x.numberofbathrooms == viewmodel.numberofbathrooms - 1 && x.numberofbathrooms == viewmodel.numberofbathrooms + 1); 

or above work?

this nice way:

var y = x.numberofbathrooms; predicate = predicate.and(x => new list<int>{y-1, y, y+1}.contains(x)); 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -