The values are all from drop down lists and either can be null or not.
Need to write a query that will work irrespective if any of the parameter
values are null or not. The below will work/return results only if all the parameters
have values and respectively all .Where statement are true. I am thinking some wild card regex to specify that the null parameters are allowed to match anything. So the more parameters the higher the search accuracy but still work if only some are supplied or none.
public ActionResult GetResults(string age, string ProgType, string Country)
{
var results = _db.Categories
.Where(c => c.CatSchema.TypeName == "Programs")
.Where(c => c.FilterValToCatMaps.Any(fm => fm.FilterValue.Value == age))
.Where(c => c.FilterValToCatMaps.Any(fm => fm.FilterValue.Value == ProgType))
.Where(c => c.RootCat.Name == Country)
.Select(c => c.RootCat);
return View();
}
You can always check for validity in the where clause
Or an example in your case might be
Alternativly have a look at the Predicate. Which could lead to a function similar to
Here you only have to include valid predicates in the list, or have the predicates themselves check for the validity of their input and returning true if they cannot filter.