/// <summary> /// Gets a string representation of the LINQ expression translated to a MongoDB query. /// </summary> /// <param name="expression">The LINQ expression.</param> /// <returns>A string.</returns> public string GetQueryText( Expression expression ) { var translatedQuery = MongoLinqTranslator.Translate(collection, expression); return(translatedQuery.ToString()); }
/// <summary> /// Gets an enumerator by executing the query. /// </summary> /// <typeparam name="T">Type element type.</typeparam> /// <param name="expression">The LINQ expression.</param> /// <returns>An enumerator for the results of the query.</returns> public IEnumerator <T> GetEnumerator <T>(Expression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } if (!typeof(IEnumerable <T>).IsAssignableFrom(expression.Type)) { throw new ArgumentException("Argument expression is not valid."); } var translatedQuery = MongoLinqTranslator.Translate(collection, expression); return(translatedQuery.GetEnumerator <T>()); }
/// <summary> /// Executes a query. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="expression">The query expression.</param> /// <returns>The result of the query.</returns> public TResult Execute <TResult>(Expression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } if (!typeof(TResult).IsAssignableFrom(expression.Type)) { throw new ArgumentException("Argument expression is not valid."); } var translatedQuery = MongoLinqTranslator.Translate(collection, expression); return((TResult)translatedQuery.Execute()); }