Example #1
0
        private void AddConstraint(PropertyCompareOperator op, IManagedProperty property, Type propertyOwner = null)
        {
            if (_pending == null)
            {
                throw new InvalidOperationException("查询构造出错:你必须先调用方法 Constrain。");
            }

            //如果没有指定属性对应的实体类型,则使用当前仓库对应的实体来作为属性的拥有者。
            var leftPropertyOwner = _pendingOwner;

            if (leftPropertyOwner == null)
            {
                leftPropertyOwner = _pending.OwnerType;
                if (_repo.EntityType.IsSubclassOf(leftPropertyOwner))
                {
                    leftPropertyOwner = _repo.EntityType;
                }
            }

            var constraint = new TwoPropertiesConstraint
            {
                Context            = this,
                LeftProperty       = _pending,
                LeftPropertyOwner  = leftPropertyOwner,
                Operator           = op,
                RightProperty      = property,
                RightPropertyOwner = propertyOwner
            };

            this.AddConstraint(constraint);

            _pending      = null;
            _pendingOwner = null;
        }
Example #2
0
        private void AddConstraint(PropertyCompareOperator op, object val)
        {
            if (_pending == null)
            {
                throw new InvalidOperationException("查询构造出错:你必须先调用方法 Constrain。");
            }

            //如果没有指定属性对应的实体类型,则使用当前仓库对应的实体来作为属性的拥有者。
            var propertyOwner = _pendingOwner;

            if (propertyOwner == null)
            {
                propertyOwner = _pending.OwnerType;
                if (_repo.EntityType.IsSubclassOf(propertyOwner))
                {
                    propertyOwner = _repo.EntityType;
                }
            }

            var constraint = new PropertyConstraint
            {
                Context      = this,
                Property     = _pending,
                ConcreteType = propertyOwner,
                Operator     = op,
                Value        = val
            };

            this.AddConstraint(constraint);

            _pending      = null;
            _pendingOwner = null;
        }
Example #3
0
        private static PropertyOperator ConvertOperator(PropertyCompareOperator pco)
        {
            var op = PropertyOperator.Equal;

            switch (pco)
            {
            case PropertyCompareOperator.Equal:
                op = PropertyOperator.Equal;
                break;

            case PropertyCompareOperator.NotEqual:
                op = PropertyOperator.NotEqual;
                break;

            case PropertyCompareOperator.Greater:
                op = PropertyOperator.Greater;
                break;

            case PropertyCompareOperator.GreaterEqual:
                op = PropertyOperator.GreaterEqual;
                break;

            case PropertyCompareOperator.Less:
                op = PropertyOperator.Less;
                break;

            case PropertyCompareOperator.LessEqual:
                op = PropertyOperator.LessEqual;
                break;

            case PropertyCompareOperator.Like:
                op = PropertyOperator.Like;
                break;

            case PropertyCompareOperator.Contains:
                op = PropertyOperator.Contains;
                break;

            case PropertyCompareOperator.StartWith:
                op = PropertyOperator.StartsWith;
                break;

            case PropertyCompareOperator.EndWith:
                op = PropertyOperator.EndsWith;
                break;

            case PropertyCompareOperator.In:
                op = PropertyOperator.In;
                break;

            case PropertyCompareOperator.NotIn:
                op = PropertyOperator.NotIn;
                break;

            default:
                break;
            }
            return(op);
        }
        internal PropertyComparisonExpression(IManagedProperty property, Type concreteType, PropertyCompareOperator op, object value)
            : base(property, concreteType)
        {
            this.Operator = op;
            this.Value = value;

            switch (op)
            {
                case PropertyCompareOperator.Equal:
                case PropertyCompareOperator.NotEqual:
                    break;
                default:
                    if (value == null)
                    {
                        throw new InvalidOperationException("null 值只能进行相等、不相等两种对比。");
                    }
                    break;
            }
        }
Example #5
0
 private static PropertyOperator ConvertOperator(PropertyCompareOperator pco)
 {
     var op = PropertyOperator.Equal;
     switch (pco)
     {
         case PropertyCompareOperator.Equal:
             op = PropertyOperator.Equal;
             break;
         case PropertyCompareOperator.NotEqual:
             op = PropertyOperator.NotEqual;
             break;
         case PropertyCompareOperator.Greater:
             op = PropertyOperator.Greater;
             break;
         case PropertyCompareOperator.GreaterEqual:
             op = PropertyOperator.GreaterEqual;
             break;
         case PropertyCompareOperator.Less:
             op = PropertyOperator.Less;
             break;
         case PropertyCompareOperator.LessEqual:
             op = PropertyOperator.LessEqual;
             break;
         case PropertyCompareOperator.Like:
             op = PropertyOperator.Like;
             break;
         case PropertyCompareOperator.Contains:
             op = PropertyOperator.Contains;
             break;
         case PropertyCompareOperator.StartWith:
             op = PropertyOperator.StartsWith;
             break;
         case PropertyCompareOperator.EndWith:
             op = PropertyOperator.EndsWith;
             break;
         case PropertyCompareOperator.In:
             op = PropertyOperator.In;
             break;
         case PropertyCompareOperator.NotIn:
             op = PropertyOperator.NotIn;
             break;
         default:
             break;
     }
     return op;
 }
Example #6
0
        private void AddConstraint(PropertyCompareOperator op, IManagedProperty property, Type propertyOwner = null)
        {
            if (_pending == null)
            {
                throw new InvalidOperationException("查询构造出错:你必须先调用方法 Constrain。");
            }

            //如果没有指定属性对应的实体类型,则使用当前仓库对应的实体来作为属性的拥有者。
            var leftPropertyOwner = _pendingOwner;
            if (leftPropertyOwner == null)
            {
                leftPropertyOwner = _pending.OwnerType;
                if (_repo.EntityType.IsSubclassOf(leftPropertyOwner))
                {
                    leftPropertyOwner = _repo.EntityType;
                }
            }

            var constraint = new TwoPropertiesConstraint
            {
                Context = this,
                LeftProperty = _pending,
                LeftPropertyOwner = leftPropertyOwner,
                Operator = op,
                RightProperty = property,
                RightPropertyOwner = propertyOwner
            };
            this.AddConstraint(constraint);

            _pending = null;
            _pendingOwner = null;
        }
Example #7
0
        private void AddConstraint(PropertyCompareOperator op, object val)
        {
            if (_pending == null)
            {
                throw new InvalidOperationException("查询构造出错:你必须先调用方法 Constrain。");
            }

            //如果没有指定属性对应的实体类型,则使用当前仓库对应的实体来作为属性的拥有者。
            var propertyOwner = _pendingOwner;
            if (propertyOwner == null)
            {
                propertyOwner = _pending.OwnerType;
                if (_repo.EntityType.IsSubclassOf(propertyOwner))
                {
                    propertyOwner = _repo.EntityType;
                }
            }

            var constraint = new PropertyConstraint
            {
                Context = this,
                Property = _pending,
                ConcreteType = propertyOwner,
                Operator = op,
                Value = val
            };
            this.AddConstraint(constraint);

            _pending = null;
            _pendingOwner = null;
        }
Example #8
0
        internal PropertyComparisonExpression(IManagedProperty property, Type concreteType, PropertyCompareOperator op, object value)
            : base(property, concreteType)
        {
            this.Operator = op;
            this.Value    = value;

            switch (op)
            {
            case PropertyCompareOperator.Equal:
            case PropertyCompareOperator.NotEqual:
                break;

            default:
                if (value == null)
                {
                    throw new InvalidOperationException("null 值只能进行相等、不相等两种对比。");
                }
                break;
            }
        }