Пример #1
0
        //public static string ISeriesCode(this SqlComparison sqlComparison) => sqlComparison.Attributes().ISeriesCode;
        //public static SqlComparison GetFromISeriesCode(this string iSeriesCode) => (from x in GetValues() where x.ISeriesCode() == iSeriesCode select x).FirstOrDefault();


        public static string ToSqlString <T>(this SqlComparison sqlComparison,
                                             string sqlExpression,
                                             IEnumerable <T> selectedValues,
                                             string sqlValuePrefix     = "",
                                             string sqlValueSuffix     = "",
                                             bool isNot                = false,
                                             SqlLogicOperator sqlAndOr = SqlLogicOperator.And
                                             )
        {
            var hasSelectedValues = selectedValues.Count() > 0;

            if (!hasSelectedValues && sqlComparison != SqlComparison.IsNull)
            {
                return(string.Empty);
            }
            var sql = new StringBuilder(" "
                                        + (sqlAndOr == SqlLogicOperator.Blank ? string.Empty : sqlAndOr.ToString()) + " "
                                        + (isNot ? " Not" : string.Empty)
                                        + sqlExpression);

            switch (sqlComparison)
            {
            case SqlComparison.IsNull: sql.Append($" Is Null"); break;

            case SqlComparison.Between: sql.Append($" Between {selectedValues.SqlLiteralBetween(sqlValuePrefix, sqlValueSuffix)}"); break;

            case SqlComparison.InList: sql.Append($" In({selectedValues.SqlLiteralIn(sqlValuePrefix, sqlValueSuffix)})"); break;

            case SqlComparison.MoreOrEqualTo: sql.Append($" >= {selectedValues.SqlLiteralMin(sqlValuePrefix, sqlValueSuffix)}"); break;

            case SqlComparison.MoreThan: sql.Append($" > {selectedValues.SqlLiteralMin(sqlValuePrefix, sqlValueSuffix)}"); break;

            case SqlComparison.LessOrEqualTo: sql.Append($" <= {selectedValues.SqlLiteralMax(sqlValuePrefix, sqlValueSuffix)}"); break;

            case SqlComparison.LessThan: sql.Append($" < {selectedValues.SqlLiteralMax(sqlValuePrefix, sqlValueSuffix)}"); break;

            default: throw new NotImplementedException($"Unknown sqlComparison: {sqlComparison}.");
            }
            return(sql.ToString());
        }
Пример #2
0
 public Predicate(string expression, SqlLogicOperator sqlOperator, object value)
 {
     this.Expression = expression;
     this.Operator   = sqlOperator.ToString();
     this.Value      = value;
 }
Пример #3
0
 public Predicate( string expression, SqlLogicOperator sqlOperator, object value )
 {
     this.Expression = expression;
     this.Operator = sqlOperator.ToString();
     this.Value = value;
 }