New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Q] Range doesn't include null fields in database #22
Labels
Comments
By the way, I got some feedbacks about including nulls in range query. There is a way to include nulls in your query:
Following class will solve this problem. But it's not a best practise so it'll not be inlcuded in AutoFilterer library by default. You can create in your project and use if you really need. using System;
using System.Linq.Expressions;
using System.Reflection;
using AutoFilterer.Types;
namespace AutoFilterer.Types
{
public class RangeOrNull<T> : Range<T> where T : struct, IComparable
{
public override Expression BuildExpression(Expression body, PropertyInfo targetProperty, PropertyInfo filterProperty, object value)
{
var rangeComparison = base.BuildExpression(body, targetProperty, filterProperty, value);
var nullComparison = Expression.Equal(Expression.Property(body, targetProperty.Name), Expression.Constant(null));
return Expression.Or(rangeComparison, nullComparison);
}
}
}
- public Range<DateTime> PublishDate { get; set; }
+ public RangeOrNull<DateTime> PublishDate { get; set; } |
enisn
changed the title
Range doesn't include null fields in database
[Q] Range doesn't include null fields in database
Jan 14, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Problem
By default,
Range<T>
doesn't include null values, it generates only GTE (>=
) and LTE (<=
) comparison. So null values don't match these arithmetic comparison because they're not greater or lesser, they're just NULL.The text was updated successfully, but these errors were encountered: