mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-21 21:12:50 +01:00
Use Expression.Constant to allow Nullable comparison
Using Expression.Constant for GetClosureOverConstant. Came to this solution from reading: http://bradwilson.typepad.com/blog/2008/07/creating-nullab.html
This commit is contained in:
parent
26d9b09bf7
commit
cd561e9f3d
@ -142,7 +142,7 @@ namespace Sieve.Services
|
|||||||
? converter.ConvertFrom(filterTerm.Value)
|
? converter.ConvertFrom(filterTerm.Value)
|
||||||
: Convert.ChangeType(filterTerm.Value, property.PropertyType);
|
: Convert.ChangeType(filterTerm.Value, property.PropertyType);
|
||||||
|
|
||||||
Expression filterValue = GetClosureOverConstant(constantVal);
|
Expression filterValue = GetClosureOverConstant(constantVal, property.PropertyType);
|
||||||
|
|
||||||
dynamic propertyValue = Expression.PropertyOrField(parameterExpression, property.Name);
|
dynamic propertyValue = Expression.PropertyOrField(parameterExpression, property.Name);
|
||||||
|
|
||||||
@ -219,12 +219,13 @@ namespace Sieve.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Workaround to ensure that the filter value gets passed as a parameter in generated SQL from EF Core
|
// 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
|
// See https://github.com/aspnet/EntityFrameworkCore/issues/3361
|
||||||
private Expression GetClosureOverConstant<T>(T constant)
|
// Expression.Constant passed the target type to allow Nullable comparison
|
||||||
|
// See http://bradwilson.typepad.com/blog/2008/07/creating-nullab.html
|
||||||
|
private Expression GetClosureOverConstant<T>(T constant, Type targetType)
|
||||||
{
|
{
|
||||||
Expression<Func<T>> closure = () => constant;
|
return Expression.Constant(constant, targetType);
|
||||||
return closure.Body;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IQueryable<TEntity> ApplySorting<TEntity>(
|
private IQueryable<TEntity> ApplySorting<TEntity>(
|
||||||
|
Loading…
Reference in New Issue
Block a user