/// <summary> /// Creates a predicate filter expression combining <see cref="FilterDescriptors"/> /// expressions with <see cref="LogicalOperator"/>. /// </summary> /// <param name="parameterExpression">The parameter expression, which will be used for filtering.</param> /// <returns>A predicate filter expression.</returns> protected override Expression CreateFilterExpression(ParameterExpression parameterExpression) { var builder = new FilterDescriptorCollectionExpressionBuilder(parameterExpression, this.FilterDescriptors, this.LogicalOperator); builder.Options.CopyFrom(this.ExpressionBuilderOptions); return builder.CreateBodyExpression(); }
/// <summary> /// Creates a predicate filter expression combining <see cref="FilterDescriptors"/> /// expressions with <see cref="LogicalOperator"/>. /// </summary> /// <param name="parameterExpression">The parameter expression, which will be used for filtering.</param> /// <returns>A predicate filter expression.</returns> protected override Expression CreateFilterExpression(ParameterExpression parameterExpression) { var builder = new FilterDescriptorCollectionExpressionBuilder(parameterExpression, this.FilterDescriptors, this.LogicalOperator); builder.Options.CopyFrom(this.ExpressionBuilderOptions); return(builder.CreateBodyExpression()); }
public static Expression <Func <T, bool> > Expression <T>(IList <IFilterDescriptor> filterDescriptors, bool checkForNull) { ParameterExpression parameterExpression = System.Linq.Expressions.Expression.Parameter(typeof(T), "item"); var builder = new FilterDescriptorCollectionExpressionBuilder(parameterExpression, filterDescriptors); builder.Options.LiftMemberAccessToNull = checkForNull; return((Expression <Func <T, bool> >)builder.CreateFilterExpression()); }
/// <summary> /// Filters a sequence of values based on a collection of <see cref="IFilterDescriptor"/>. /// </summary> /// <param name="source">The source.</param> /// <param name="filterDescriptors">The filter descriptors.</param> /// <param name="logicalOperator">And or Or?.</param> /// <returns> /// An <see cref="IQueryable" /> that contains elements from the input sequence /// that satisfy the conditions specified by each filter descriptor in <paramref name="filterDescriptors" />. /// </returns> public static IQueryable Where(this IQueryable source, IEnumerable <IFilterDescriptor> filterDescriptors, FilterCompositionLogicalOperator logicalOperator = FilterCompositionLogicalOperator.And) { if (filterDescriptors.Any()) { var parameterExpression = Expression.Parameter(source.ElementType, "item"); var expressionBuilder = new FilterDescriptorCollectionExpressionBuilder(parameterExpression, filterDescriptors, logicalOperator);//Modified By Moravej expressionBuilder.Options.LiftMemberAccessToNull = source.Provider.IsLinqToObjectsProvider(); var predicate = expressionBuilder.CreateFilterExpression(); return(source.Where(predicate)); } return(source); }
/// <summary> /// Filters a sequence of values based on a collection of <see cref="IFilterDescriptor"/>. /// </summary> /// <param name="source">The source.</param> /// <param name="filterDescriptors">The filter descriptors.</param> /// <returns> /// An <see cref="IQueryable" /> that contains elements from the input sequence /// that satisfy the conditions specified by each filter descriptor in <paramref name="filterDescriptors" />. /// </returns> public static IQueryable Where(this IQueryable source, IList <IFilterDescriptor> filterDescriptors) { if (filterDescriptors.Any()) { var parameterExpression = Expression.Parameter(source.ElementType, "item"); var expressionBuilder = new FilterDescriptorCollectionExpressionBuilder(parameterExpression, filterDescriptors); expressionBuilder.Options.LiftMemberAccessToNull = source.Provider.IsLinqToObjectsProvider(); var predicate = expressionBuilder.CreateFilterExpression(); return(source.Where(predicate)); } return(source); }
private static LambdaExpression GetFilter(this string filter, Type type, string parameterName = "i") { if (string.IsNullOrEmpty(filter)) { return(null); } var parameterExpression = Expression.Parameter(type, parameterName); var expressionBuilder = new FilterDescriptorCollectionExpressionBuilder(parameterExpression, FilterDescriptorFactory.Create(filter)); expressionBuilder.Options.LiftMemberAccessToNull = false; return(expressionBuilder.CreateFilterExpression()); }
/// <summary> /// Where /// </summary> /// <param name="expression"></param> /// <param name="filterDescriptors"></param> /// <param name="isLiftedToNull"></param> /// <returns></returns> public static Expression Where(this Expression expression, IEnumerable <IFilterDescriptor> filterDescriptors, bool isLiftedToNull = false) { if (filterDescriptors.Any()) { var parameterExpression = Expression.Parameter(expression.GetUnderlyingElementType(), "item"); var expressionBuilder = new FilterDescriptorCollectionExpressionBuilder(parameterExpression, filterDescriptors); //expressionBuilder.Options.LiftMemberAccessToNull = source.Provider.IsLinqToObjectsProvider(); expressionBuilder.Options.LiftMemberAccessToNull = isLiftedToNull; var predicate = expressionBuilder.CreateFilterExpression(); return(expression.Where(predicate)); } return(expression); }
/// <summary> /// Filters a sequence of values based on a collection of <see cref="IFilterDescriptor"/>. /// </summary> /// <param name="source">The source.</param> /// <param name="filterDescriptors">The filter descriptors.</param> /// <returns> /// An <see cref="IQueryable" /> that contains elements from the input sequence /// that satisfy the conditions specified by each filter descriptor in <paramref name="filterDescriptors" />. /// </returns> public static IQueryable WhereV <TViewModel>(this IQueryable source, IEnumerable <IFilterDescriptor> filterDescriptors) { if (filterDescriptors.Any()) { var viewType = typeof(TViewModel); ConvertViewModelToModelFilterDescriptor(viewType, filterDescriptors); var parameterExpression = Expression.Parameter(source.ElementType, "item"); //ViewModelToModelFilter var expressionBuilder = new FilterDescriptorCollectionExpressionBuilder(parameterExpression, filterDescriptors); expressionBuilder.Options.LiftMemberAccessToNull = source.Provider.IsLinqToObjectsProvider(); var predicate = expressionBuilder.CreateFilterExpression(); return(source.Where(predicate)); } return(source); }
/// <summary> /// Filters a sequence of values based on a collection of <see cref="IFilterDescriptor"/>. /// </summary> /// <param name="source">The source.</param> /// <param name="filterDescriptors">The filter descriptors.</param> /// <returns> /// An <see cref="IQueryable" /> that contains elements from the input sequence /// that satisfy the conditions specified by each filter descriptor in <paramref name="filterDescriptors" />. /// </returns> public static IQueryable Where(this IQueryable source, IEnumerable<IFilterDescriptor> filterDescriptors) { if (filterDescriptors.Any()) { var parameterExpression = Expression.Parameter(source.ElementType, "item"); var expressionBuilder = new FilterDescriptorCollectionExpressionBuilder(parameterExpression, filterDescriptors); expressionBuilder.Options.LiftMemberAccessToNull = source.Provider.IsLinqToObjectsProvider(); var predicate = expressionBuilder.CreateFilterExpression(); return source.Where(predicate); } return source; }