Пример #1
0
        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);
        }
Пример #2
0
        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);
        }