Esempio n. 1
0
        private string BuildOutput(bool includeSelection = true)
        {
            var sb = new StringBuilder();

            var offset = Limit?.Offset ?? 0;
            var fetch  = Limit?.Fetch ?? 0;

            if (includeSelection)
            {
                var topStr = offset == 0 && fetch > 0 ? $"top({fetch}) " : "";
                sb.Append($"select {topStr}{Selection}");
            }

            if (From != null)
            {
                sb.AppendLine();
                sb.Append($"from {From}");
            }

            if (Joins.Count > 0)
            {
                sb.AppendLine();
                sb.Append($"{string.Join(Environment.NewLine, Joins)}");
            }

            if (Where != null)
            {
                sb.AppendLine();
                sb.Append($"where {Where}");
            }

            if (GroupBys.Any())
            {
                sb.AppendLine();
                sb.Append($"group by {GroupBys}");
            }

            if (OrderBys.Any())
            {
                sb.AppendLine();
                sb.Append($"order by {string.Join(", ", OrderBys)}");
            }

            if (Limit != null && Limit.Offset > 0)
            {
                sb.AppendLine();
                sb.Append($"{Limit}");
            }

            sb.AppendLine();

            return(sb.ToString());
        }
Esempio n. 2
0
        private string BuildOutput(bool includeSelection = true)
        {
            var sb = new StringBuilder();

            if (includeSelection)
            {
                sb.Append($"select {Selection}");
            }

            if (From != null)
            {
                sb.AppendLine();
                sb.Append($"from {From}");
            }

            if (Joins.Count > 0)
            {
                sb.AppendLine();
                sb.Append($"{string.Join(Environment.NewLine, Joins)}");
            }

            if (Where != null)
            {
                sb.AppendLine();
                sb.Append($"where {Where}");
            }

            if (GroupBys.Any())
            {
                sb.AppendLine();
                sb.Append($"group by {GroupBys}");
            }

            if (OrderBys.Any())
            {
                sb.AppendLine();
                sb.Append($"order by {string.Join(", ", OrderBys)}");
            }

            sb.AppendLine();

            return(sb.ToString());
        }