Пример #1
0
        protected string TranslateFilterExpression(FilterExpression filter)
        {
            var left = TranslateLeftFilterOperand(filter);
            var right = TranslateRightFilterOperand(filter);
            string op = null;
            switch (filter.Operator)
            {
                case Operators.And:
                    op = "AND";
                    break;

                case Operators.Or:
                    op = "OR";
                    break;

                case Operators.Equal:
                    op = "=";
                    break;

                case Operators.NotEqual:
                    op = "!=";
                    break;

                case Operators.GreaterOrEqual:
                    op = ">=";
                    break;

                case Operators.LessOrEqual:
                    op = "<=";
                    break;

                case Operators.GreaterThan:
                    op = ">";
                    break;

                case Operators.LessThan:
                    op = "<=";
                    break;

                case Operators.IsNull:
                    op = "IS";
                    break;

                case Operators.IsNotNull:
                    op = "IS NOT";
                    break;

                case Operators.StartsWith:
                case Operators.EndsWith:
                case Operators.Contains:
                    op = "LIKE";
                    break;

                case Operators.NotStartsWith:
                case Operators.NotEndsWith:
                case Operators.NotContains:
                    op = "NOT LIKE";
                    break;

                case Operators.In:
                    op = "IN";
                    break;

                case Operators.NotIn:
                    op = "NOT IN";
                    break;
            }
            return String.Format(BinaryFormat, left, op, right);
        }
Пример #2
0
        protected string TranslateRightFilterOperand(FilterExpression filter)
        {
            if (filter.Right != null) return TranslateFilterExpression(filter.Right);
            if (!ReferenceEquals(filter.RightColumn, null)) return TranslateColumn(filter.RightColumn);
            if (filter.Value == null) return "NULL";
            if (filter.Value is bool) return (bool)filter.Value ? "1" : "0";

            return filter.Value.GetType().IsArray
                ? String.Format("({0})", TranslateValueArray((IEnumerable) filter.Value))
                : TranslateParameter(filter.Value);
        }
Пример #3
0
 protected string TranslateLeftFilterOperand(FilterExpression filter)
 {
     if (filter.Left != null) return TranslateFilterExpression(filter.Left);
     if (!ReferenceEquals(filter.LeftColumn, null)) return TranslateColumn(filter.LeftColumn);
     throw new Exception("Unexpected left operand in FilterExpression");
 }
Пример #4
0
 public Query Where(FilterExpression filter)
 {
     return ((Query) this).Where(filter);
 }
Пример #5
0
        public Query Where(FilterExpression filter)
        {
            _filter = ReferenceEquals(null, _filter)
                ? filter
                : new FilterExpression(_filter, filter, Operators.And);

            return this;
        }
Пример #6
0
        public Command Where(FilterExpression filter)
        {
            if (CommandType == CommandType.Insert)
                throw CommandError.FilterInsertError(Table);

            Filter = filter;
            return this;
        }