protected override Expression VisitExtension(Expression node) { QueryNode query = node as QueryNode; if (query != null) { return(Expression.Constant(query.Execute(sqliteProvider, options))); } else { return(base.VisitExtension(node)); } }
public override object Execute(Expression inputExpression) { Stopwatch watch = Stopwatch.StartNew(); Expression partiallyEvaluatedExpression = PartialEvaluator.Eval(inputExpression, CanBeEvaluatedStatically); QueryExecutionOptions options = new QueryExecutionOptions(); Expression expression = new ConvertToQueryAstVisitor(options).Visit(partiallyEvaluatedExpression); // options have been initialized by ConvertToQueryAstVisitor, start logging: if (options.HasLoggers) { options.WriteLogLine("Input expression: " + inputExpression); options.WriteLogLine("Partially evaluated expression: " + partiallyEvaluatedExpression); options.WriteLogLine("Converted to Query AST: " + expression); } expression = new OptimizeQueryExpressionVisitor().Visit(expression); if (options.HasLoggers) { options.WriteLogLine("Optimized Query AST: " + expression); options.WriteLogLine("Query preparation time: " + watch.Elapsed); } object result; // If the whole query was converted, execute it: QueryNode query = expression as QueryNode; if (query != null) { result = query.Execute(this, options); } else { // Query not converted completely: we have to use a LINQ-To-Objects / LINQ-To-Profiler mix expression = new ExecuteAllQueriesVisitor(this, options).Visit(expression); if (expression.Type.IsValueType) { expression = Expression.Convert(expression, typeof(object)); } var lambdaExpression = Expression.Lambda <Func <object> >(expression); result = lambdaExpression.Compile()(); } watch.Stop(); options.WriteLogLine("Total query execution time: " + watch.Elapsed); return(result); }