private static Expression CreateLambdaExpression(ParameterExpression parameter, string property, object value, LambdaCompare compare)
        {
            //var propertyExpression = Expression.Convert(Expression.Property(parameter, property), value.GetType());
            var propertyExpression = Expression.Property(parameter, property);
            var valueExpression    = Expression.Constant(value);

            switch (compare)
            {
            case LambdaCompare.LessThan:
                return(Expression.LessThan(propertyExpression, valueExpression));

            case LambdaCompare.LessThanOrEqual:
                return(Expression.LessThanOrEqual(propertyExpression, valueExpression));

            case LambdaCompare.GreaterThan:
                return(Expression.GreaterThan(propertyExpression, valueExpression));

            case LambdaCompare.GreaterThanOrEqual:
                return(Expression.GreaterThanOrEqual(propertyExpression, valueExpression));

            case LambdaCompare.Equal:
                return(Expression.Equal(propertyExpression, valueExpression));

            case LambdaCompare.NotEqual:
                return(Expression.NotEqual(propertyExpression, valueExpression));

            case LambdaCompare.Contains:
                return(Expression.Call(propertyExpression, MethodCreator.CreateStringContainMethod(), valueExpression));

            case LambdaCompare.Unknown:
            default:
                throw new ArgumentOutOfRangeException(nameof(compare), compare, null);
            }
        }
Exemplo n.º 2
0
        private MethodCallExpression CreateIncludeMethodCallExpression(Expression pExpression, bool hasncludeFilter)
        {
            MethodInfo include;
            Expression includePropertyExpr;
            var        list = Properties.Values.Where(p => !p.ShouldInclude && p.ComputedExpression != null).Select(p => p.ComputedExpression).ToList();

            if (hasncludeFilter && list.Any())
            {
                var w         = MethodCreator.CreateGenericEnumerableWhereMethod(Type);
                var whereExpr = list.Aggregate(Expression.AndAlso);
                var l         = Expression.Lambda(whereExpr, false, ParameterExpression);
                var c         = Expression.Property(Parent.ParameterExpression, NodeName);
                includePropertyExpr = Expression.Call(null, w, new Expression[] { c, l });
                include             = Depth > 1 ? MethodCreator.CreateGenericThenIncludeMethod(Parent, this, typeof(IEnumerable <>)) : MethodCreator.CreateGenericIncludeMethod(Parent, this, typeof(IEnumerable <>));
            }
            else
            {
                includePropertyExpr = Expression.Property(Parent.ParameterExpression, NodeName);
                include             = Depth > 1 ? MethodCreator.CreateGenericThenIncludeMethod(Parent, this, typeof(ICollection <>)) : MethodCreator.CreateGenericIncludeMethod(Parent, this, typeof(ICollection <>));
            }

            var lambda = Expression.Lambda(includePropertyExpr, false, Parent.ParameterExpression);
            var exp    = Expression.Call(null, include, new[] { pExpression, Expression.Quote(lambda) });

            return(exp);
        }
Exemplo n.º 3
0
        private Expression CreateAnyExpression()
        {
            if (WherePredictExpression == null)
            {
                return(null);
            }

            var wInfo  = MethodCreator.CreateGenericAnyMethod(Type);
            var lambda = Expression.Lambda(WherePredictExpression, false, ParameterExpression);
            var c      = Expression.Property(Parent.ParameterExpression, NodeName);
            var exp    = Expression.Call(null, wInfo, new Expression[] { c, Expression.Quote(lambda) });

            return(exp);
        }
Exemplo n.º 4
0
        private static IQueryable <T> CreateQueryWhere <T>(IQueryable <T> queryable, ExpressionNode node)
        {
            var predict = node.CreateWherePredictExpression();

            if (predict == null)
            {
                return(queryable);
            }

            var wInfo  = MethodCreator.CreateGenericQueryableWhereMethod(node.Type);
            var lambda = Expression.Lambda(node.WherePredictExpression, false, node.ParameterExpression);
            var exp    = Expression.Call(null, wInfo, new[] { queryable.Expression, Expression.Quote(lambda) });

            return(queryable.Provider.CreateQuery <T>(exp));
        }