public override Expression Bind(ProjectionExpression projection, ProjectionBindingContext context, MethodCallExpression node, IEnumerable<Expression> arguments) { LambdaExpression aggregator; if (node.Method.Name.EndsWith("Async")) { aggregator = CreateAsyncAggregator(); } else { aggregator = CreateSyncAggregator(); } var source = projection.Source; var argument = arguments.FirstOrDefault(); if (argument != null && ExtensionExpressionVisitor.IsLambda(argument)) { source = BindPredicate(projection, context, source, argument); } source = new TakeExpression(source, 1); var serializer = context.SerializerRegistry.GetSerializer(typeof(int)); var accumulator = new AccumulatorExpression(typeof(int), AccumulatorType.Count, null); var serializationAccumulator = new SerializationExpression( accumulator, new BsonSerializationInfo("__agg0", serializer, serializer.ValueType)); var rootAccumulator = new RootAccumulatorExpression(source, serializationAccumulator); return new ProjectionExpression( rootAccumulator, serializationAccumulator, aggregator); }
public override Expression Bind(ProjectionExpression projection, ProjectionBindingContext context, MethodCallExpression node, IEnumerable<Expression> arguments) { var aggregator = CreateAggregator(node.Method.Name, projection.Projector.Type); var source = projection.Source; var argument = arguments.FirstOrDefault(); if (argument != null && ExtensionExpressionVisitor.IsLambda(argument)) { source = BindPredicate(projection, context, source, argument); } source = new TakeExpression(source, 2); return new ProjectionExpression( source, projection.Projector, aggregator); }
protected internal virtual Expression VisitTake(TakeExpression node) { return(node.Update( Visit(node.Source), Visit(node.Count))); }
private void TranslateTake(TakeExpression node) { Translate(node.Source); _stages.Add(new BsonDocument("$limit", (int)((ConstantExpression)node.Count).Value)); }
protected internal virtual Expression VisitTake(TakeExpression node) { return node.Update( Visit(node.Source), Visit(node.Count)); }
private BsonValue TranslateTake(TakeExpression node) { var arguments = new BsonArray(); var skipNode = node.Source as SkipExpression; if (skipNode != null) { arguments.Add(TranslateValue(skipNode.Source)); arguments.Add(TranslateValue(skipNode.Count)); } else { arguments.Add(TranslateValue(node.Source)); } arguments.Add(TranslateValue(node.Count)); return new BsonDocument("$slice", arguments); }
private void VisitTake(TakeExpression node) { Visit(node.Source); _stages.Add(new BsonDocument("$limit", node.Count)); }