protected override IQueryable <TSourceData> DefaultFilter(IQueryable <TSourceData> source, RangeTuple <TVal> key) { if (_sourceExpression == null) { throw new Exception("Trying to call FilterDelegate with null source expression"); } if (TreatEqualDateAsWholeDay) { if (typeof(TVal) == typeof(DateTime) || typeof(TVal) == typeof(DateTime?)) { if (key.HasFrom && key.HasTo) { var from = (DateTime)(object)key.From; var to = (DateTime)(object)key.To; if (from.Date == to.Date) { key.From = (TVal)(object)new DateTime(from.Year, from.Month, from.Day, 00, 00, 00); key.To = (TVal)(object)new DateTime(from.Year, from.Month, from.Day, 23, 59, 59); } } } } if (key.HasTo && key.HasFrom) { var between = LambdaHelpers.BetweenLambdaExpression(_sourceExpression, key.From.ExtractValueFromNullable(), key.To.ExtractValueFromNullable(), _inclusive); return(ReflectionCache.CallWhere(source, between)); } if (key.HasTo) { ExpressionType lt = _inclusive ? ExpressionType.LessThanOrEqual : ExpressionType.LessThan; var less = LambdaHelpers.ConstantBinaryLambdaExpression(lt, _sourceExpression, key.To.ExtractValueFromNullable()); return(ReflectionCache.CallWhere(source, less)); } if (key.HasFrom) { ExpressionType gt = _inclusive ? ExpressionType.GreaterThanOrEqual : ExpressionType.GreaterThan; var greater = LambdaHelpers.ConstantBinaryLambdaExpression(gt, _sourceExpression, key.From.ExtractValueFromNullable()); return(ReflectionCache.CallWhere(source, greater)); } return(source); }