值集合的字段
Inheritance: CodeArt.DomainDriven.DataAccess.ObjectField
コード例 #1
0
        /// <summary>
        /// 创建基础值集合的值字段
        /// </summary>
        /// <param name="ownerType"></param>
        /// <param name="propertyType"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static GeneratedField CreatePrimitiveValue(Type ownerType, ValueListField field)
        {
            var            valueType = field.ValueType;
            DomainProperty property  = null;
            DbFieldType    fieldType = DbFieldType.Common;

            if (valueType == typeof(string))
            {
                var maxLength = field.Tip.GetMaxLength();
                if (maxLength < 300)
                {
                    //如果value的字符串类型长度小于300,那么就可以参与索引
                    fieldType = DbFieldType.NonclusteredIndex;
                }
                property = new StringProperty(ownerType, PrimitiveValueName, maxLength, field.Tip.IsASCIIString());
            }
            else
            {
                fieldType = DbFieldType.NonclusteredIndex;
                property  = new CustomProperty(ownerType, valueType, PrimitiveValueName);
            }

            var attr = new PropertyRepositoryAttribute()
            {
                Property = property
            };

            return(new GeneratedField(attr, PrimitiveValueName, GeneratedFieldType.PrimitiveValue, fieldType));
        }
コード例 #2
0
        /// <summary>
        /// 获取集合类型的数据字段
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="propertyType"></param>
        /// <returns></returns>
        private bool TryGetListField(PropertyRepositoryAttribute attribute, bool isSnapshot, ref IDataField result)
        {
            var elementType = attribute.GetElementType();

            if (DomainObject.IsValueObject(elementType))
            {
                //值对象
                var field = new ValueObjectListField(attribute);
                //当值对象A引用了值对象A时,会造成死循环
                //var mapper = DataMapperFactory.Create(elementType);
                //var childs = mapper.GetObjectFields(elementType, isSnapshot);
                //field.AddChilds(childs);

                result = field;
                return(true);
            }
            else if (DomainObject.IsAggregateRoot(elementType))
            {
                //引用了根对象
                var field = new AggregateRootListField(attribute);
                result = field;
                return(true);
            }
            else if (DomainObject.IsEntityObject(elementType))
            {
                //引用了内部实体对象
                var field = new EntityObjectListField(attribute);
                //当成员对象A引用了成员对象A时,会造成死循环
                //var mapper = DataMapperFactory.Create(elementType);
                //var childs = mapper.GetObjectFields(elementType, isSnapshot);
                //field.AddChilds(childs);

                result = field;
                return(true);
            }
            else if (elementType.IsList())
            {
                throw new DomainDesignException(Strings.NestedCollection);
            }
            else
            {
                //值集合
                var field = new ValueListField(attribute);
                result = field;
                return(true);
            }
        }
コード例 #3
0
        /// <summary>
        /// 获取集合类型的数据字段
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="propertyType"></param>
        /// <returns></returns>
        private static bool TryGetListField(PropertyRepositoryAttribute attribute, bool isSnapshot, ref IDataField result)
        {
            var elementType = attribute.PropertyType.ResolveElementType();

            if (DomainObject.IsValueObject(elementType))
            {
                //值对象
                var field  = new ValueObjectListField(attribute);
                var childs = GetObjectFields(elementType, isSnapshot);
                field.AddChilds(childs);

                result = field;
                return(true);
            }
            else if (DomainObject.IsAggregateRoot(elementType))
            {
                //引用了根对象
                var field = new AggregateRootListField(attribute);
                result = field;
                return(true);
            }
            else if (DomainObject.IsEntityObject(elementType))
            {
                //引用了内部实体对象
                var field  = new EntityObjectListField(attribute);
                var childs = GetObjectFields(elementType, isSnapshot);
                field.AddChilds(childs);

                result = field;
                return(true);
            }
            else if (IsList(elementType))
            {
                throw new DomainDesignException(Strings.NestedCollection);
            }
            else
            {
                //值集合
                var field = new ValueListField(attribute);
                result = field;
                return(true);
            }
        }
コード例 #4
0
        /// <summary>
        /// 创建基础值集合的值字段
        /// </summary>
        /// <param name="ownerType"></param>
        /// <param name="propertyType"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static GeneratedField CreatePrimitiveValue(Type ownerType, ValueListField field)
        {
            var            valueType = field.ValueType;
            DomainProperty property  = null;

            if (valueType == typeof(string))
            {
                property = new StringProperty(ownerType, PrimitiveValueName, field.Tip.GetMaxLength(), field.Tip.IsASCIIString());
            }
            else
            {
                property = new CustomProperty(ownerType, valueType, PrimitiveValueName);
            }

            var attr = new PropertyRepositoryAttribute()
            {
                Property = property
            };

            return(new GeneratedField(attr, PrimitiveValueName, GeneratedFieldType.PrimitiveValue, DbFieldType.NonclusteredIndex));
        }
コード例 #5
0
        private static bool FillFields(List <IDataField> fields, IDataField current)
        {
            string name = string.IsNullOrEmpty(current.Name) ? current.GetPropertyName() : current.Name;

            switch (current.FieldType)
            {
            case DataFieldType.GeneratedField:
            {
                fields.Add(current);         //对于生成的键,直接追加
                return(true);
            }

            case DataFieldType.Value:
            {
                var valueField = current as ValueField;
                //存值
                var field = new ValueField(current.Tip, valueField.DbFieldTypes.ToArray())
                {
                    Name = name,
                    ParentMemberField = current.ParentMemberField
                };
                fields.Add(field);
                return(true);
            }

            case DataFieldType.ValueList:
            {
                //普通值的集合,会被转换成逗号分隔的字符串存放,因此作为字段输入
                var vlf   = current as ValueListField;
                var field = new ValueListField(vlf.Tip)
                {
                    Name = name
                };
                fields.Add(field);
                return(true);
            }

            case DataFieldType.EntityObject:
            case DataFieldType.EntityObjectPro:
            case DataFieldType.AggregateRoot:
            {
                //存外键即可
                var idAttr = DomainProperty.GetProperty(current.Tip.PropertyType, EntityObject.IdPropertyName).RepositoryTip;

                var field = new ValueField(idAttr)
                {
                    Name = _getIdName(name),
                    ParentMemberField = current
                };
                fields.Add(field);
                return(true);
            }

            case DataFieldType.ValueObject:
            {
                var primaryKey = GeneratedField.CreateValueObjectPrimaryKey(current.Tip.PropertyType);
                var field      = new ValueField(primaryKey.Tip)
                {
                    Name = _getIdName(name),
                    ParentMemberField = current
                };
                fields.Add(field);
                return(true);
            }

            default:
            {
                current.Name = name;         //对于其他的类型,只是赋值字段名称
                break;
            }
            }
            return(false);
        }