Exemple #1
0
        public object Execute(Expression expression)
        {
            // Translate the expression tree
            expression = LinqTranslatorVisitor.Translate(expression);

            // Covert prediate (scalar) expressions to a source query
            if (expression is APredicateExpression predicate)
            {
                FieldExpression value = new FieldExpression(predicate, "Scalar", "Value");
                expression = new ScalarExpression(null, value);
            }

            // Covert aggregate (scalar) expressions to a source query
            if (expression is AggregateExpression aggregate)
            {
                FieldExpression value = new FieldExpression(aggregate, "Scalar", "Value");
                expression = new ScalarExpression(aggregate.Source, value);
            }

            // Execute the query
            if (expression is ASourceExpression source)
            {
                return(connection.ExecuteQuery(source, visitor));
            }

            throw new NotSupportedException("The expression could not be converted to sql.");
        }
Exemple #2
0
        /// <summary>
        /// Translates the specified expression and its subtree to an <see cref="AExpression"/>.
        /// </summary>
        /// <param name="expression">The expression to modify.</param>
        /// <returns>The converted expression tree.</returns>
        public static Expression Translate(Expression expression)
        {
            LinqTranslatorVisitor visitor = new LinqTranslatorVisitor();

            return(visitor.Visit(expression));
        }