示例#1
0
        /// <summary>
        /// Appends a $bucketAuto stage to the pipeline.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="aggregate">The aggregate.</param>
        /// <param name="groupBy">The expression providing the value to group by.</param>
        /// <param name="buckets">The number of buckets.</param>
        /// <param name="options">The options (optional).</param>
        /// <returns>The fluent aggregate interface.</returns>
        public static IAggregateFluent <AggregateBucketAutoResult <TValue> > BucketAuto <TResult, TValue>(
            this IAggregateFluent <TResult> aggregate,
            Expression <Func <TResult, TValue> > groupBy,
            int buckets,
            AggregateBucketAutoOptions options = null)
        {
            Ensure.IsNotNull(aggregate, nameof(aggregate));
            Ensure.IsNotNull(groupBy, nameof(groupBy));

            var groupByDefinition = new ExpressionAggregateExpressionDefinition <TResult, TValue>(groupBy, aggregate.Options.TranslationOptions);

            return(aggregate.BucketAuto(groupByDefinition, buckets, options));
        }
示例#2
0
        /// <summary>
        /// Appends a $bucketAuto stage to the pipeline.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <typeparam name="TNewResult">The type of the new result.</typeparam>
        /// <param name="aggregate">The aggregate.</param>
        /// <param name="groupBy">The expression providing the value to group by.</param>
        /// <param name="buckets">The number of buckets.</param>
        /// <param name="output">The output projection.</param>
        /// <param name="options">The options (optional).</param>
        /// <returns>The fluent aggregate interface.</returns>
        public static IAggregateFluent <TNewResult> BucketAuto <TResult, TValue, TNewResult>(
            this IAggregateFluent <TResult> aggregate,
            Expression <Func <TResult, TValue> > groupBy,
            int buckets,
            Expression <Func <IGrouping <TValue, TResult>, TNewResult> > output,
            AggregateBucketAutoOptions options = null)
        {
            Ensure.IsNotNull(aggregate, nameof(aggregate));
            Ensure.IsNotNull(groupBy, nameof(groupBy));
            Ensure.IsNotNull(output, nameof(output));

            var groupByDefinition = new ExpressionAggregateExpressionDefinition <TResult, TValue>(groupBy, aggregate.Options.TranslationOptions);
            var outputDefinition  = new ExpressionBucketOutputProjection <TResult, TValue, TNewResult>(x => default(TValue), output, aggregate.Options.TranslationOptions);

            return(aggregate.BucketAuto(groupByDefinition, buckets, outputDefinition, options));
        }