private static void AddWhere(StringBuilder sb, ASpecification <T> spec) { bool needScobe = spec._specifications.Count > 1; if (needScobe) { sb.Append('('); } sb.Append(spec._innerOperation); foreach (var specification in spec._specifications) { switch (specification.Key) { case EOperation.AND: sb.Append("AND "); break; case EOperation.OR: sb.Append("OR "); break; default: throw new Exception($"Unknown operation {specification.Key}"); } AddWhere(sb, specification.Value); } if (needScobe) { sb.Append(')'); } }
public static string Querry(ASpecification <T> spec) { var sb = new StringBuilder(spec._innerOperation.Data); AddSelect(sb); sb.Append(' '); AddTableName(sb); sb.Append(" WHERE "); AddWhere(sb, spec); return(sb.ToString()); }