So i have a one class to deal with strings, splitting them and setting the whole expression (There is more than just contriesNames, but iam not introducing it here to make it simpler):
public class DealWithExpression
{
public void DealWithExpression(Params params)
{
string[] countriesNames = {};
if(params.Countries != null)
countriesNames = params.Countries.Split(','); // params got Countries string prop.
HandleQuery(someQuery, x => countriesNames.Contains(db.table.Name))
}
}
And i have another class that gets the query from database and is supposed to filter with expected Filter
expressions:
public class DealWithQuery()
{
HandleQuery(IQueryable<TEntity> inputQuery, Expression<Func<T, bool>> Filter)
{
var query = inputQuery;
if(Filter != null)
{
query.Where(Filter);
}
}
}
I think the expression i store in Filter
object doesn't store the string[] countriesNames
and it doesn't know what to compare against, but iam not sure. I dont want to store additional string arrays in DealWithQuery class, is there a way to do it? To avoid cluttering the classes?
, Func> filter = list => str => list.Contains(str);
var queryParameters = new List() {"Nike", "Sweden", "Large"};
var countries = new List() {"Germany", "Sweden", "Denmark"};
var countryFilter = filter(countries);
var filteredList = queryParameters.Where(countryFilter);`
– Rasmus Edvardsen Sep 01 '20 at 10:05