public override string ToString() { var sb = new StringBuilder("SELECT "); if (IsDistinctQuery) { sb.Append("DISTINCT "); } if (TopExpression != null) { sb.Append("TOP (").Append(TopExpression).Append(") "); } if (SelectProjection != null) { sb.Append(SelectProjection); } if (SqlTables.Count > 0) { sb.Append(" FROM "); sb.Append(SqlTables.First()); SqlTables.Skip(1).Aggregate(sb, (builder, table) => builder.Append(", ").Append(table)); } if (WhereCondition != null) { sb.Append(" WHERE ").Append(WhereCondition); } if (GroupByExpression != null) { sb.Append(" GROUP BY ").Append(GroupByExpression); } if (Orderings.Count > 0) { sb.Append(" ORDER BY "); Orderings.Aggregate( sb, (builder, ordering) => builder .Append(ordering.Expression) .Append(" ") .Append(ordering.OrderingDirection.ToString().ToUpper())); } foreach (var combinedStatement in SetOperationCombinedStatements) { sb .Append(" ") .Append(combinedStatement.SetOperation.ToString().ToUpper()) .Append(" (") .Append(combinedStatement.SqlStatement) .Append(")"); } return(sb.ToString()); }
public override string ToString() { var sb = new StringBuilder("SELECT "); if (IsDistinctQuery) { sb.Append("DISTINCT "); } if (TopExpression != null) { sb.Append("TOP (").Append(FormattingExpressionTreeVisitor.Format(TopExpression)).Append(") "); } if (SelectProjection != null) { sb.Append(FormattingExpressionTreeVisitor.Format(SelectProjection)); } if (SqlTables.Count > 0) { sb.Append(" FROM "); sb.Append(SqlTables.First()); SqlTables.Skip(1).Aggregate(sb, (builder, table) => builder.Append(", ").Append(table)); } if (WhereCondition != null) { sb.Append(" WHERE ").Append(FormattingExpressionTreeVisitor.Format(WhereCondition)); } if (GroupByExpression != null) { sb.Append(" GROUP BY ").Append(FormattingExpressionTreeVisitor.Format(GroupByExpression)); } if (Orderings.Count > 0) { sb.Append(" ORDER BY "); Orderings.Aggregate( sb, (builder, ordering) => builder .Append(FormattingExpressionTreeVisitor.Format(ordering.Expression)) .Append(" ") .Append(ordering.OrderingDirection.ToString().ToUpper())); } return(sb.ToString()); }