diff --git a/Sieve/Services/SieveProcessor.cs b/Sieve/Services/SieveProcessor.cs index 7930b2d..5402602 100644 --- a/Sieve/Services/SieveProcessor.cs +++ b/Sieve/Services/SieveProcessor.cs @@ -127,10 +127,12 @@ namespace Sieve.Services var converter = TypeDescriptor.GetConverter(property.PropertyType); var parameter = Expression.Parameter(typeof(TEntity), "e"); - dynamic filterValue = Expression.Constant( - converter.CanConvertFrom(typeof(string)) ? - converter.ConvertFrom(filterTerm.Value) : - Convert.ChangeType(filterTerm.Value, property.PropertyType)); + + dynamic constantVal = converter.CanConvertFrom(typeof(string)) + ? converter.ConvertFrom(filterTerm.Value) + : Convert.ChangeType(filterTerm.Value, property.PropertyType); + + Expression filterValue = GetClosureOverConstant(constantVal); dynamic propertyValue = Expression.PropertyOrField(parameter, property.Name); @@ -201,6 +203,14 @@ namespace Sieve.Services return result; } + //Workaround to ensure that the filter value gets passed as a parameter in generated SQL from EF Core + //See https://github.com/aspnet/EntityFrameworkCore/issues/3361 + private Expression GetClosureOverConstant(T constant) + { + Expression> closure = () => constant; + return closure.Body; + } + private IQueryable ApplySorting( ISieveModel model, IQueryable result,