Skip to content

Commit

Permalink
fix(filter): Fixed linq2sql for string contains comparison ignore case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamess-Lucass committed Dec 13, 2024
1 parent 4423492 commit f5d0682
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/GoatQuery/src/Evaluator/FilterEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ public static Result<Expression> Evaluate(QueryExpression expression, ParameterE
case Keywords.Contains:
var identifier = (Identifier)exp.Left;

var method = identifier.Value.GetType().GetMethod("Contains", new[] { value?.Value.GetType(), typeof(StringComparison) });
var toLowerMethod = identifier.Value.GetType().GetMethod("ToLower", Type.EmptyTypes);

return Expression.Call(property, method, value, Expression.Constant(StringComparison.OrdinalIgnoreCase));
var propertyToLower = Expression.Call(property, toLowerMethod);
var valueToLower = Expression.Call(value, toLowerMethod);

var containsMethod = identifier.Value.GetType().GetMethod("Contains", new[] { value?.Value.GetType() });

return Expression.Call(propertyToLower, containsMethod, valueToLower);
case Keywords.Lt:
return Expression.LessThan(property, value);
case Keywords.Lte:
Expand Down

0 comments on commit f5d0682

Please sign in to comment.