コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 protected internal virtual Expression VisitTake(TakeExpression node)
 {
     return(node.Update(
                Visit(node.Source),
                Visit(node.Count)));
 }
コード例 #4
0
        private void TranslateTake(TakeExpression node)
        {
            Translate(node.Source);

            _stages.Add(new BsonDocument("$limit", (int)((ConstantExpression)node.Count).Value));
        }
コード例 #5
0
 protected internal virtual Expression VisitTake(TakeExpression node)
 {
     return node.Update(
         Visit(node.Source),
         Visit(node.Count));
 }
コード例 #6
0
        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);
        }
コード例 #7
0
 private void VisitTake(TakeExpression node)
 {
     Visit(node.Source);
     _stages.Add(new BsonDocument("$limit", node.Count));
 }