public void PipelineStageDefinitionBuilder_Group_with_expressions_should_throw_with_LINQ3() { var stageDefinition = PipelineStageDefinitionBuilder.Group((BsonDocument x) => 1, x => new { Count = x.Count() }); var exception = Record.Exception(() => Linq3TestHelpers.Render(stageDefinition, BsonDocumentSerializer.Instance, LinqProvider.V3)); exception.Should().BeOfType <InvalidOperationException>(); }
public void PipelineStageDefinitionBuilder_Group_with_expressions_should_work_with_LINQ2() { var stageDefinition = PipelineStageDefinitionBuilder.Group((BsonDocument x) => 1, x => new { Count = x.Count() }); var stage = Linq3TestHelpers.Render(stageDefinition, BsonDocumentSerializer.Instance, LinqProvider.V2); var expectedStages = new[] { "{ $group : { _id : 1, Count : { $sum : 1 } } }" }; Linq3TestHelpers.AssertStages(new[] { stage }, expectedStages); }
public void PipelineStageDefinitionBuilder_Group_with_projection_to_TOutput_should_work( [Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider) { var stageDefinition = PipelineStageDefinitionBuilder.Group <BsonDocument, BsonDocument>("{ _id : 1, Count : { $sum : 1 } }"); var stage = Linq3TestHelpers.Render(stageDefinition, BsonDocumentSerializer.Instance, linqProvider); var expectedStages = new[] { "{ $group : { _id : 1, Count : { $sum : 1 } } }" }; Linq3TestHelpers.AssertStages(new[] { stage }, expectedStages); }
/// <summary> /// Appends a group stage to the pipeline. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <typeparam name="TKey">The type of the key.</typeparam> /// <typeparam name="TNewResult">The type of the new result.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="id">The id.</param> /// <param name="group">The group projection.</param> /// <returns> /// The fluent aggregate interface. /// </returns> public static IAggregateFluent <TNewResult> Group <TResult, TKey, TNewResult>(this IAggregateFluent <TResult> aggregate, Expression <Func <TResult, TKey> > id, Expression <Func <IGrouping <TKey, TResult>, TNewResult> > group) { Ensure.IsNotNull(aggregate, nameof(aggregate)); if (aggregate.Database.Client.Settings.LinqProvider == LinqProvider.V2) { return(aggregate.AppendStage(PipelineStageDefinitionBuilder.Group(id, group))); } else { var(groupStage, projectStage) = PipelineStageDefinitionBuilder.GroupForLinq3(id, group); return(aggregate.AppendStage(groupStage).AppendStage(projectStage)); } }
/// <summary> /// Appends a group stage to the pipeline. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <typeparam name="TKey">The type of the key.</typeparam> /// <typeparam name="TNewResult">The type of the new result.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="id">The id.</param> /// <param name="group">The group projection.</param> /// <returns> /// The fluent aggregate interface. /// </returns> public static IAggregateFluent <TNewResult> Group <TResult, TKey, TNewResult>(this IAggregateFluent <TResult> aggregate, Expression <Func <TResult, TKey> > id, Expression <Func <IGrouping <TKey, TResult>, TNewResult> > group) { Ensure.IsNotNull(aggregate, nameof(aggregate)); return(aggregate.AppendStage(PipelineStageDefinitionBuilder.Group(id, group))); }
/// <summary> /// Appends a group stage to the pipeline. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="group">The group projection.</param> /// <returns> /// The fluent aggregate interface. /// </returns> public static IAggregateFluent <BsonDocument> Group <TResult>(this IAggregateFluent <TResult> aggregate, ProjectionDefinition <TResult, BsonDocument> group) { Ensure.IsNotNull(aggregate, nameof(aggregate)); return(aggregate.AppendStage(PipelineStageDefinitionBuilder.Group(group))); }