I'm building expression from parameters for filtering and came across a problem, expression looks something like this:
(x =>
(!specParams.CarModelId.HasValue || x.CarModelId == specParams.CarModelId.Value) &&
(string.IsNullOrWhiteSpace(specParams.CarModelName) || x.CarModel.Name.NormalizedContains(specParams.CarModelName))
)
problem acquires with NormalizedContains()
extension method that I wrote, as it can't be translated as an Expression, the extension method:
public static bool NormalizedContains(this string @string, string value) =>
@string.ToLower().Contains(value.ToLower()); // may have other manipulations with strings before comparing
How can I rewrite the extension method as an Expression?