Example #1
0
        protected override Expression VisitMethodCall(MethodCallExpression m)
        {
            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Where")
            {
                this.Visit(m.Arguments[0]);
                LambdaExpression           lambda       = (LambdaExpression)StripQuotes(m.Arguments[1]);
                ConditionExpressionVisitor whereVisitor = new ConditionExpressionVisitor();
                whereVisitor.Translate(lambda.Body, tr);
                return(m);
            }
            else if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Select")
            {
                this.Visit(m.Arguments[0]);
                LambdaExpression        lambda        = (LambdaExpression)StripQuotes(m.Arguments[1]);
                SelectExpressionVisitor selectVisitor = new SelectExpressionVisitor();
                selectVisitor.Translate(lambda, tr);
                return(m);
            }
            else if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Count")
            {
                tr.HasStatictisc  = true;
                tr.StatictiscVerb = "Count";
                this.Visit(m.Arguments[0]);
                if (m.Arguments.Count == 2)
                {
                    throw new NotSupportedException("Count clause not support parameter,use where clause instead.");
                }
                return(m);
            }
            else if (m.Method.DeclaringType == typeof(Queryable) && (m.Method.Name == "OrderByDescending" || m.Method.Name == "OrderBy"))
            {
                Visit(m.Arguments[0]);
                LambdaExpression         lambda       = (LambdaExpression)StripQuotes(m.Arguments[1]);
                OrderByExpressionVisitor orderVisitor = new OrderByExpressionVisitor(m.Method.Name);
                orderVisitor.Translate(lambda.Body, tr);
                return(m);
            }
            else if (m.Method.Name == "Sum" ||
                     m.Method.Name == "Average" ||
                     m.Method.Name == "Max" ||
                     m.Method.Name == "Min" ||
                     m.Method.Name == "Count")
            {
                throw new NotSupportedException("Statictisc is not support yet.");
            }

            else if (m.Method.Name == "GroupBy")
            {
                throw new NotSupportedException("GroupBy is not support yet.");
            }
            throw new NotSupportedException(string.Format("The method '{0}' is not supported", m.Method.Name));
        }
Example #2
0
        protected override Expression VisitMethodCall(MethodCallExpression m)
        {
            if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Where") {

                this.Visit(m.Arguments[0]);
                LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
                ConditionExpressionVisitor whereVisitor = new ConditionExpressionVisitor();
                whereVisitor.Translate(lambda.Body, tr);
                return m;
            }
            else if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Select")
            {
                this.Visit(m.Arguments[0]);
                LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
                SelectExpressionVisitor selectVisitor = new SelectExpressionVisitor();
                selectVisitor.Translate(lambda,tr);
                return m;
            }
            else if (m.Method.DeclaringType == typeof(Queryable) && m.Method.Name == "Count")
            {
                tr.HasStatictisc = true;
                tr.StatictiscVerb = "Count";
                this.Visit(m.Arguments[0]);
                if (m.Arguments.Count == 2)
                {
                    throw new NotSupportedException("Count clause not support parameter,use where clause instead.");
                }
                return m;
            }
            else if (m.Method.DeclaringType == typeof(Queryable) && (m.Method.Name == "OrderByDescending" || m.Method.Name == "OrderBy"))
            {
                Visit(m.Arguments[0]);
                LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
                OrderByExpressionVisitor orderVisitor = new OrderByExpressionVisitor(m.Method.Name);
                orderVisitor.Translate(lambda.Body,tr);
                return m;
            }
            else if (m.Method.Name == "Sum"
                || m.Method.Name == "Average"
                || m.Method.Name == "Max"
                || m.Method.Name == "Min"
                || m.Method.Name == "Count")
            {
                throw new NotSupportedException("Statictisc is not support yet.");
            }

            else if (m.Method.Name == "GroupBy")
            {
                throw new NotSupportedException("GroupBy is not support yet.");
            }
            throw new NotSupportedException(string.Format("The method '{0}' is not supported", m.Method.Name));
        }