protected internal virtual Expression VisitSelectMany(SelectManyExpression node)
 {
     return(node.Update(
                Visit(node.Source),
                Visit(node.CollectionSelector),
                Visit(node.ResultSelector)));
 }
Пример #2
0
        private void TranslateSelectMany(SelectManyExpression node)
        {
            Translate(node.Source);

            var isLeftOuterJoin = false;
            IFieldExpression field;
            var collectionSelector = node.CollectionSelector as PipelineExpression;
            if (collectionSelector != null)
            {
                var defaultIfEmpty = collectionSelector.Source as DefaultIfEmptyExpression;
                if (defaultIfEmpty != null)
                {
                    isLeftOuterJoin = true;
                    field = defaultIfEmpty.Source as IFieldExpression;
                }
                else
                {
                    field = collectionSelector.Source as IFieldExpression;
                }
            }
            else
            {
                field = node.CollectionSelector as IFieldExpression;
            }

            if (field == null)
            {
                var message = string.Format("The collection selector must be a field: {0}", node.ToString());
                throw new NotSupportedException(message);
            }

            BsonValue unwindValue = "$" + field.FieldName;
            var groupJoin = node.Source as GroupJoinExpression;
            if (groupJoin != null && isLeftOuterJoin)
            {
                unwindValue = new BsonDocument
                {
                    { "path", unwindValue },
                    { "preserveNullAndEmptyArrays", true }
                };
            }

            _stages.Add(new BsonDocument("$unwind", unwindValue));

            var projectValue = TranslateProjectValue(node.ResultSelector);
            _stages.Add(new BsonDocument("$project", projectValue));
        }
        private void VisitSelectMany(SelectManyExpression node)
        {
            Visit(node.Source);

            var field = node.CollectionSelector as ISerializationExpression;
            if (field == null || field.SerializationInfo.ElementName == null)
            {
                var message = string.Format("The collection selector must be an ISerializationExpression: {0}", node.ToString());
                throw new NotSupportedException(message);
            }

            _stages.Add(new BsonDocument("$unwind", "$" + field.SerializationInfo.ElementName));

            var projection = AggregateProjectionTranslator.TranslateProject(node.ResultSelector);
            _stages.Add(new BsonDocument("$project", projection));
        }
 protected internal virtual Expression VisitSelectMany(SelectManyExpression node)
 {
     return node.Update(
         Visit(node.Source),
         Visit(node.CollectionSelector),
         Visit(node.ResultSelector));
 }
        private void TranslateSelectMany(SelectManyExpression node)
        {
            Translate(node.Source);

            var field = node.CollectionSelector as IFieldExpression;
            if (field == null)
            {
                var message = string.Format("The collection selector must be a field: {0}", node.ToString());
                throw new NotSupportedException(message);
            }

            _stages.Add(new BsonDocument("$unwind", "$" + field.FieldName));

            var projectValue = TranslateProjectValue(node.ResultSelector);
            _stages.Add(new BsonDocument("$project", projectValue));
        }