Beispiel #1
0
        public IQueryable <TEntity> Apply(IQueryable <TEntity> query)
        {
            var terms = GetValidTerms().ToArray();

            if (!terms.Any())
            {
                return(query);
            }
            var modifiedQuery = query;

            foreach (var term in terms)
            {
                var propertyInfo = ExpressionHelper.GetPropertyInfo <TEntity>(term.Name);
                var obj          = ExpressionHelper.Parameter <TEntity>();
                //build  the linq expression backwards
                //query = query.where(x => x.Property == "Value");

                //x.property
                var left = ExpressionHelper.GetPropertyExpression(obj, propertyInfo);
                //"Value"
                var right = Expression.Constant(term.Value);
                //x.property == "value"
                var ExpressionProvider   = new DecimalToIntSearchExpressionProvider();
                var comparisonExpression = ExpressionProvider.GetComparison(left, term.operators, right);
//                var comparisonExpression = Expression.Equal(left, right);
                //x=> x.property == value
                var lambdaExpression = ExpressionHelper.GetLambda <TEntity, bool>(obj, comparisonExpression);
                //query = query.Where
                modifiedQuery = ExpressionHelper.CallWhere(modifiedQuery, lambdaExpression);
            }

            return(modifiedQuery);
        }
Beispiel #2
0
 public SearchableDecimalAttribute()
 {
     ExpressionProvider = new DecimalToIntSearchExpressionProvider();
 }