コード例 #1
0
        public string BuildSqlString()
        {
            var stringBuilder = new StringBuilder();

            if (string.IsNullOrEmpty(SelectPart) || FromParts.Count == 0)
            {
                throw new InvalidOperationException("A query must have a select part and at least one from part.");
            }

            stringBuilder.Append($"select {SelectPart}");
            stringBuilder.Append($" from {SeparatedStringBuilder.Build(", ", FromParts)}");

            if (WhereParts.Count > 0)
            {
                stringBuilder.Append($" where {SeparatedStringBuilder.Build(" and ", WhereParts)}");
            }

            if (OrderByParts.Count > 0)
            {
                stringBuilder.Append($" order by {SeparatedStringBuilder.Build(", ", OrderByParts)}");
            }

            if (FetchPart != null)
            {
                stringBuilder.Append($" {FetchPart}");
            }

            return(stringBuilder.ToString());
        }
コード例 #2
0
 public void AddOrderByPart(IEnumerable <string> orderings)
 {
     OrderByParts.Insert(0, SeparatedStringBuilder.Build(", ", orderings));
 }