Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Core.Persistence/Dynamic/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Filter
public string Operator { get; set; }
public string? Value { get; set; }
public string? Logic { get; set; }
public bool CaseSensitive { get; set; } = false;
public IEnumerable<Filter>? Filters { get; set; }

public Filter()
Expand Down
27 changes: 25 additions & 2 deletions src/Core.Persistence/Dynamic/IQueryableDynamicFilterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public static class IQueryableDynamicFilterExtensions
{ "startswith", "StartsWith" },
{ "endswith", "EndsWith" },
{ "contains", "Contains" },
{ "doesnotcontain", "Contains" }
{ "doesnotcontain", "Contains" },
{ "in", "In" },
{ "between", "Between" }
};

public static IQueryable<T> ToDynamic<T>(this IQueryable<T> query, DynamicQuery dynamicQuery)
Expand Down Expand Up @@ -93,7 +95,28 @@ public static string Transform(Filter filter, IList<Filter> filters)
if (filter.Operator == "doesnotcontain")
where.Append($"(!np({filter.Field}).{comparison}(@{index.ToString()}))");
else if (comparison is "StartsWith" or "EndsWith" or "Contains")
where.Append($"(np({filter.Field}).{comparison}(@{index.ToString()}))");
{
if (!filter.CaseSensitive)
{
where.Append($"(np({filter.Field}).ToLower().{comparison}(@{index.ToString()}.ToLower()))");
}
else
{
where.Append($"(np({filter.Field}).{comparison}(@{index.ToString()}))");
}
}
else if (filter.Operator == "in")
{
where.Append($"np({filter.Field}) in ({filter.Value})");
}
else if (filter.Operator == "between")
{
var values = filter.Value.Split(',');
if (values.Length != 2)
throw new ArgumentException("Invalid Value for 'between' operator");

where.Append($"(np({filter.Field}) >= {values[0]} and np({filter.Field}) <= {values[1]})");
}
else
where.Append($"np({filter.Field}) {comparison} @{index.ToString()}");
else if (filter.Operator is "isnull" or "isnotnull")
Expand Down