I'm trying to understand predicate builder
so I can apply it to a web app I'm creating.
Basically I have 4 parameters that come in through a POST request, 'name', 'location', 'age', 'gender', and I have to filter out people from a database table based on these parameters.
problem is, every parameter has the possibility of being 'All' (meaning, if name = 'All', that means don't filter out people by name, if location = 'All' don't filter people by location etc...).
So one way I thought of doing this is to get all people into a list, and have 4 if statements:
if (name != 'All') {
//filter list of people by name string
}
if (location != 'All') {
//filter list of people by location
}
but I don't want to do this, I want to use predicate builder to build the linq expression and only get a list of people who match the parameters, but I don't understand what predicate builder is doing.
This is the site I'm looking at but it doesn't really explain what's going on, and I don't know how to apply it to my situation