// Queryable's "single value" standard query operators call this method.
        // It is also called from QueryableTerraServerData.GetEnumerator().
        public TResult Execute <TResult>(Expression expression)
        {
            var interpretationResult = new LinqToSqlInterpretator().Visit(new MSSqlQueryBuilder(), Evaluator.PartialEval(expression));
            var queryResult          = dbQuery.Get(interpretationResult.SqlQuery, expression.Type);

            return((TResult)queryResult);
        }
Example #2
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            if (node.Arguments[0].NodeType == ExpressionType.Call)
            {
                this.Visit(node.Arguments[0]);
            }

            if (node.Method.Name.Equals("FirstOrDefault", StringComparison.OrdinalIgnoreCase) ||
                node.Method.Name.Equals("First", StringComparison.OrdinalIgnoreCase) ||
                node.Method.Name.Equals("SingleOrDefault", StringComparison.OrdinalIgnoreCase) ||
                node.Method.Name.Equals("Single", StringComparison.OrdinalIgnoreCase))
            {
                sqlQueryBuilder.AddTake(TypeSystem.GetElementType(node.Arguments[0].Type), "1");
            }

            string arg = null;

            if (node.Arguments.Count == 2)
            {
                arg = new LinqToSqlInterpretator()
                      .Visit(sqlQueryBuilder.Clone(), node.Arguments[1])
                      .SqlQuery;
            }

            if (node.Method.Name.Equals("Where", StringComparison.OrdinalIgnoreCase))
            {
                sqlQueryBuilder.AddWhere(TypeSystem.GetElementType(node.Arguments[0].Type), arg);
            }

            if (node.Method.Name.Equals("OrderBy", StringComparison.OrdinalIgnoreCase))
            {
                sqlQueryBuilder.AddOrderBy(TypeSystem.GetElementType(node.Arguments[0].Type), arg);
            }

            if (node.Method.Name.Equals("Skip", StringComparison.OrdinalIgnoreCase))
            {
                sqlQueryBuilder.AddSkip(TypeSystem.GetElementType(node.Arguments[0].Type), arg);
            }

            if (node.Method.Name.Equals("Take", StringComparison.OrdinalIgnoreCase))
            {
                sqlQueryBuilder.AddTake(TypeSystem.GetElementType(node.Arguments[0].Type), arg);
            }

            if (node.Method.Name.Equals("Select", StringComparison.OrdinalIgnoreCase))
            {
                sqlQueryBuilder.AddSelect(TypeSystem.GetElementType(node.Arguments[0].Type), arg);
            }

            return(node);
        }
        public object Execute(Expression expression)
        {
            var interpretationResult = new LinqToSqlInterpretator().Visit(new MSSqlQueryBuilder(), Evaluator.PartialEval(expression));

            return(dbQuery.Get(interpretationResult.SqlQuery, expression.Type));
        }