Skip to content

Commit 2d753ee

Browse files
authored
ignore case during contains query (#77)
1 parent 5cc92ee commit 2d753ee

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/Extensions/QueryableExtension.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,20 @@ public static (IQueryable, int?) Apply<T>(this IQueryable<T> queryable, Query qu
5555
property = propertyName;
5656
}
5757

58-
if (operand.Equals("contains", StringComparison.OrdinalIgnoreCase))
58+
if (typeof(T).GetProperties().FirstOrDefault(x => x.Name.Equals(property, StringComparison.OrdinalIgnoreCase))?.PropertyType == typeof(string))
5959
{
60-
where.Append($"{property}.{_filterOperations[operand]}({value})");
60+
if (operand.Equals("contains", StringComparison.OrdinalIgnoreCase))
61+
{
62+
where.Append($"{property}.ToLower().Contains({value}.ToLower())");
63+
}
64+
else
65+
{
66+
where.Append($"{property}.ToLower() {_filterOperations[operand]} {value}.ToLower()");
67+
}
6168
}
62-
else if (typeof(T).GetProperties().FirstOrDefault(x => x.Name.Equals(property, StringComparison.OrdinalIgnoreCase))?.PropertyType == typeof(string))
69+
else if (operand.Equals("contains", StringComparison.OrdinalIgnoreCase))
6370
{
64-
where.Append($"{property}.ToLower() {_filterOperations[operand]} {value}.ToLower()");
71+
where.Append($"{property}.{_filterOperations[operand]}({value})");
6572
}
6673
else if (typeof(T).GetProperties().FirstOrDefault(x => x.Name.Equals(property, StringComparison.OrdinalIgnoreCase))?.PropertyType == typeof(Guid))
6774
{

0 commit comments

Comments
 (0)