示例#1
0
        /// <summary>No need to call this directly, required of IQueryProvider</summary>
        public IQueryable <TResult> CreateQuery <TResult>(Expression expression)
        {
            if (!typeof(IQueryable <TResult>).IsAssignableFrom(expression.Type))
            {
                throw new ArgumentOutOfRangeException(nameof(expression));
            }

            var queryable = new MongoAggregationQueryable <TResult> {
                Provider   = this,
                Expression = expression
            };

            return(queryable);
        }
示例#2
0
        /// <summary>
        /// Gets our custom Aggregation Framework based queryable from a MongoCollection
        /// </summary>
        /// <typeparam name="TMongoDocument">The document type stored in the collection</typeparam>
        /// <param name="collection">A Mongo collection to query</param>
        /// <param name="allowMongoDiskUse">
        /// If true, MongoDB can use the disk for the query if possible.  If false it won't but there's
        /// a risk that the query is too big to be handled in memory.
        /// </param>
        /// <param name="loggingDelegate">Callback function for debug logging</param>
        /// <returns>An IQueryable for running Linq queries against</returns>
        public static IQueryable <TMongoDocument> QueryablePlusPlus <TMongoDocument>(this IMongoCollection <TMongoDocument> collection, bool allowMongoDiskUse, Action <string> loggingDelegate)
        {
            var queryable = new MongoAggregationQueryable <TMongoDocument>();

            queryable.Expression = Expression.Constant(queryable);
            queryable.Provider   = new MongoAggregationQueryProvider <TMongoDocument>(collection)
            {
                Queryable         = queryable,
                LoggingDelegate   = loggingDelegate,
                AllowMongoDiskUse = allowMongoDiskUse
            };

            return(queryable);
        }