public SelectExpression FormatComplexTypeSubquery(
            SelectExpression subquery,
            IDbCommandExpressionBuilder builder,
            ExpressionVisitor visitor)
        {
            builder.Append("(");

            builder.IncreaseIndent();
            builder.AppendLine();

            var projection   = subquery.Projection.Flatten().Body;
            var leafGatherer = new ProjectionLeafGatheringExpressionVisitor();

            leafGatherer.Visit(projection);

            if (leafGatherer.GatheredExpressions.Count == 1 &&
                string.IsNullOrEmpty(leafGatherer.GatheredExpressions.Keys.Single()) &&
                !(projection is SqlColumnExpression || projection is SqlAliasExpression))
            {
                subquery
                    = subquery.UpdateProjection(
                          new ServerProjectionExpression(
                              new SqlAliasExpression(
                                  subquery.Projection.ResultLambda.Body,
                                  "$c")));
            }

            // Strip DefaultIfEmptyExpressions out because FOR JSON will leave out the null values

            var strippingVisitor = new DefaultIfEmptyStrippingExpressionVisitor();

            subquery = strippingVisitor.VisitAndConvert(subquery, nameof(FormatComplexTypeSubquery));

            // Visit and print the subquery

            subquery = visitor.VisitAndConvert(subquery, nameof(FormatComplexTypeSubquery));

            builder.AppendLine();
            builder.Append("FOR JSON PATH");

            builder.DecreaseIndent();
            builder.AppendLine();

            builder.Append(")");

            return(subquery);
        }
        public SelectExpression Format(SelectExpression subquery, IDbCommandExpressionBuilder builder, ExpressionVisitor visitor)
        {
            builder.Append("(");

            builder.IncreaseIndent();
            builder.AppendLine();

            subquery = visitor.VisitAndConvert(subquery, nameof(Format));

            builder.AppendLine();
            // TODO: Don't use INCLUDE_NULL_VALUES
            builder.Append("FOR JSON PATH, INCLUDE_NULL_VALUES");

            builder.DecreaseIndent();
            builder.AppendLine();

            builder.Append(")");

            return(subquery);
        }