/// <summary> /// Executes the Linq expression /// </summary> /// <param retval="expression">An expression tree that represents a LINQ query.</param> /// <returns>The execute.</returns> public object ExecuteQuery <T>(Expression expression) { expression = PartialEvaluator.Eval(expression, this.CanBeEvaluatedLocally); var translator = new MongoQueryTranslator(); translator.CollectionName = this.CollectionName; var results = translator.Translate(expression); _results = results; var executor = new MongoQueryExecutor(this.DB, results); object retval = null; if (results.Select != null) { MethodInfo mi = executor.GetType().GetMethod("Execute"); var method = mi.MakeGenericMethod(results.OriginalSelectType); retval = method.Invoke(executor, new object[] {}); } else { retval = executor.Execute <T>(); } return(retval); }
/// <summary> /// Initializes a new instance of the <see cref="MongoQueryExecutor"/> class. /// </summary> /// <param retval="mongo">The database on which the query will be executed.</param> /// <param retval="translationResults">The results of the query translation</param> public MongoQueryExecutor(IMongoDatabase db, QueryTranslationResults translationResults) { _db = db; _translationResults = translationResults; }