StringBuilder IQueryElement.ToString(StringBuilder sb, Dictionary <IQueryElement, IQueryElement> dic) { if (dic.ContainsKey(this)) { return(sb.Append("...")); } dic.Add(this, this); sb.Append("SELECT "); if (IsDistinct) { sb.Append("DISTINCT "); } if (SkipValue != null) { sb.Append("SKIP "); SkipValue.ToString(sb, dic); sb.Append(" "); } if (TakeValue != null) { sb.Append("TAKE "); TakeValue.ToString(sb, dic); sb.Append(" "); } sb.AppendLine(); if (Columns.Count == 0) { sb.Append("\t*, \n"); } else { for (var i = 0; i < Columns.Count; i++) { var c = Columns[i]; sb.Append("\t"); ((IQueryElement)c).ToString(sb, dic); sb .Append(" as ") .Append(c.Alias ?? "c" + (i + 1)) .Append(", \n"); } } sb.Length -= 3; dic.Remove(this); return(sb); }
public override StringBuilder ToString(StringBuilder sb, Dictionary <IQueryElement, IQueryElement> dic) { if (dic.ContainsKey(this)) { return(sb.Append("...")); } dic.Add(this, this); sb.Append("SELECT "); if (IsDistinct) { sb.Append("DISTINCT "); } if (SkipValue != null) { sb.Append("SKIP "); SkipValue.ToString(sb, dic); sb.Append(" "); } if (TakeValue != null) { sb.Append("TAKE "); TakeValue.ToString(sb, dic); sb.Append(" "); } sb.AppendLine(); if (Columns.Count == 0) { sb.Append("\t*, \n"); } else { foreach (var c in Columns) { sb.Append("\t"); c.ToString(sb, dic); sb.Append(" as ").Append(c.Alias ?? "c" + (Columns.IndexOf(c) + 1)).Append(", \n"); } } sb.Length -= 3; dic.Remove(this); return(sb); }
StringBuilder IQueryElement.ToString(StringBuilder sb, Dictionary <IQueryElement, IQueryElement> dic) { if (dic.ContainsKey(this)) { return(sb.Append("...")); } dic.Add(this, this); sb.Append("SELECT "); if (IsDistinct) { sb.Append("DISTINCT "); } if (SkipValue != null) { sb.Append("SKIP "); SkipValue.ToString(sb, dic); sb.Append(' '); } if (TakeValue != null) { sb.Append("TAKE "); TakeValue.ToString(sb, dic); sb.Append(' '); } sb.AppendLine(); if (Columns.Count == 0) { sb.Append("\t*, \n"); } else { var columnNames = new List <string>(); var csb = new StringBuilder(); var maxLength = 0; for (var i = 0; i < Columns.Count; i++) { csb.Length = 0; var c = Columns[i]; csb.Append('\t'); csb .Append('t') .Append(c.Parent?.SourceID ?? -1) #if DEBUG .Append('[').Append(c.ColumnNumber).Append(']') #endif .Append('.') .Append(c.Alias ?? "c" + (i + 1)); var columnName = csb.ToString(); columnNames.Add(columnName); maxLength = Math.Max(maxLength, columnName.Length); } for (var i = 0; i < Columns.Count; i++) { var c = Columns[i]; var columnName = columnNames[i]; sb.Append(columnName) .Append(' ', maxLength - columnName.Length) .Append(" = "); csb.Length = 0; c.Expression.ToString(csb, dic); var expressionText = csb.ToString(); if (expressionText.Contains("\n")) { var ident = "\t" + new string(' ', maxLength + 2); expressionText = expressionText.Replace("\n", "\n" + ident); } sb .Append(expressionText) .Append(", \n"); } } sb.Length -= 3; dic.Remove(this); return(sb); }