예제 #1
0
        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(')');
            }
        }
예제 #2
0
        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());
        }