Ejemplo n.º 1
0
        public static IManagedProperty Find(this ManagedPropertyList list, string property, bool ignoreCase)
        {
            if (ignoreCase)
            {
                for (int i = 0, c = list.Count; i < c; i++)
                {
                    var item = list[i];
                    if (item.Name.EqualsIgnoreCase(property))
                    {
                        return(item);
                    }
                }
                return(null);
            }

            return(list.Find(property));
        }
Ejemplo n.º 2
0
        private IConstraint CreatePropertyConstraint(string property, string comparison, string value)
        {
            var mp = _properties.Find(property, true);

            if (mp == null)
            {
                throw new InvalidProgramException(string.Format("查询条件解析出错,没有找到名称为 {0} 的属性。", property));
            }

            var column = _mainTable.Column(mp);

            var op = PropertyOperator.Equal;

            switch (comparison.ToLower())
            {
            case "eq":
                op = PropertyOperator.Equal;
                break;

            case "ne":
                op = PropertyOperator.NotEqual;
                break;

            case "gt":
                op = PropertyOperator.Greater;
                break;

            case "ge":
                op = PropertyOperator.GreaterEqual;
                break;

            case "lt":
                op = PropertyOperator.Less;
                break;

            case "le":
                op = PropertyOperator.LessEqual;
                break;

            default:
                throw new NotSupportedException("不支持这个操作符:" + comparison + "。");
            }

            return(_f.Constraint(column, op, value));
        }
Ejemplo n.º 3
0
        private void DealConstraintWord(string part)
        {
            //part 表示列名
            if (_column == null)
            {
                //可能使用了引用属性,例如表达式:User.Name eq 'huqf'
                var properties = part.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                if (properties.Length > 1)
                {
                    ITableSource lastTable = _mainTable;
                    for (int i = 0; i < properties.Length; i++)
                    {
                        var property = properties[i];
                        var mp       = lastTable.EntityRepository.EntityMeta.ManagedProperties.GetCompiledProperties().Find(property);
                        if (mp == null)
                        {
                            throw new InvalidProgramException(string.Format("查询条件解析出错,没有找到名称为 {0} 的属性。", property));
                        }

                        var refProperty = mp as IRefEntityProperty;
                        if (refProperty != null)
                        {
                            lastTable = _f.FindOrCreateJoinTable(_query, lastTable, refProperty);
                        }
                        else
                        {
                            _column = lastTable.Column(mp);
                        }
                    }
                    if (_column == null)
                    {
                        throw new InvalidProgramException(string.Format("{0} 查询条件出错:属性表达式不能以引用实体属性结尾。", part));
                    }
                }
                else
                {
                    var mp = _properties.Find(part, true);
                    if (mp == null)
                    {
                        throw new InvalidProgramException(string.Format("查询条件解析出错,没有找到名称为 {0} 的属性。", part));
                    }
                    _column = _mainTable.Column(mp);
                }
            }
            //part 表示操作符
            else if (_comparison == null)
            {
                _comparison = part;
            }
            //part 表示值
            else
            {
                var propertyConstraint = CreateColumnConstraint(_comparison, part);
                if (_concat.HasValue && _current != null)
                {
                    _current = _f.Binary(_current, _concat.Value, propertyConstraint);
                    _concat  = null;
                }
                else
                {
                    _current = propertyConstraint;
                }

                _column     = null;
                _comparison = null;
            }
        }