コード例 #1
0
        /// <summary>
        /// 初始化属性映射信息。
        /// </summary>
        /// <param name="info">实体映射信息。</param>
        /// <param name="propertyInfo">属性信息。</param>
        /// <returns></returns>
        private static PropertyMapInfo InitPropertyInfo(PropertyMapInfo info, PropertyInfo propertyInfo)
        {
            if (info == null)
            {
                info = new PropertyMapInfo();
            }

            if (string.IsNullOrEmpty(info.FieldName))
            {
                info.FieldName = propertyInfo.Name;
            }

            info.ReflectionInfo = propertyInfo;
            return(info);
        }
コード例 #2
0
        /// <summary>
        /// 根据映射特性设置属性的映射信息。
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="mapInfo"></param>
        private static void InitMapInfo(PropertyMappingAttribute mapping, PropertyMapInfo mapInfo)
        {
            mapInfo.FieldName    = mapping.ColumnName;
            mapInfo.Description  = mapping.Description;
            mapInfo.GenerateType = mapping.GenerateType;

            if (mapping.GetFlag(PropertyMappingAttribute.SetMark.DataType))
            {
                mapInfo.DataType = mapping.DataType;
            }

            if (mapping.GetFlag(PropertyMappingAttribute.SetMark.IsPrimaryKey))
            {
                mapInfo.IsPrimaryKey = mapping.IsPrimaryKey;
            }

            if (mapping.GetFlag(PropertyMappingAttribute.SetMark.IsDeletedKey))
            {
                mapInfo.IsDeletedKey = mapping.IsDeletedKey;
            }

            if (mapping.DefaultValue != null)
            {
                mapInfo.DefaultValue          = PropertyValue.NewValue(mapping.DefaultValue, mapInfo.ReflectionInfo.PropertyType);
                mapInfo.DefaultValueFormatter = mapping.DefaultValueFormatter;
            }

            if (mapping.GetFlag(PropertyMappingAttribute.SetMark.Length))
            {
                mapInfo.Length = mapping.Length;
            }

            if (mapping.GetFlag(PropertyMappingAttribute.SetMark.Precision))
            {
                mapInfo.Precision = mapping.Precision;
            }

            if (mapping.GetFlag(PropertyMappingAttribute.SetMark.Scale))
            {
                mapInfo.Scale = mapping.Scale;
            }
        }
コード例 #3
0
        /// <summary>
        /// 注册基本的实体属性。
        /// </summary>
        /// <param name="propertyName">属性名称。</param>
        /// <param name="propertyType">属性类型。</param>
        /// <param name="entityType">实体类型。</param>
        /// <param name="info">属性映射信息。</param>
        /// <returns>一个 <see cref="IProperty"/> 对象。</returns>
        public static IProperty RegisterProperty(string propertyName, Type propertyType, Type entityType, PropertyMapInfo info = null)
        {
            var propertyInfo = entityType.GetProperty(propertyName);

            if (propertyInfo == null)
            {
                throw new PropertyNotFoundException(propertyName);
            }

            return(RegisterProperty(propertyInfo, entityType, info));
        }
コード例 #4
0
        /// <summary>
        /// 注册基本的实体属性。
        /// </summary>
        /// <typeparam name="TEntity">实体的类型。</typeparam>
        /// <param name="expression">指定注册的属性的表达式。</param>
        /// <param name="info">属性映射信息。</param>
        /// <returns>一个 <see cref="IProperty"/> 对象。</returns>
        public static IProperty RegisterProperty <TEntity>(Expression <Func <TEntity, object> > expression, PropertyMapInfo info = null) where TEntity : IEntity
        {
            var propertyInfo = PropertySearchVisitor.FindProperty(expression);

            if (propertyInfo == null)
            {
                throw new InvalidOperationException(SR.GetString(SRKind.InvalidRegisterExpression));
            }

            return(RegisterProperty(propertyInfo, typeof(TEntity), info));
        }
コード例 #5
0
        /// <summary>
        /// 注册基本的实体属性。
        /// </summary>
        /// <param name="propertyInfo">属性信息。</param>
        /// <param name="entityType">实体类型。</param>
        /// <param name="info">属性映射信息。</param>
        /// <returns>一个 <see cref="IProperty"/> 对象。</returns>
        private static IProperty RegisterProperty(PropertyInfo propertyInfo, Type entityType, PropertyMapInfo info = null)
        {
            var property = new GeneralProperty
            {
                Name       = propertyInfo.Name,
                Type       = propertyInfo.PropertyType,
                EntityType = entityType,
                Info       = InitPropertyInfo(info, propertyInfo)
            };

            return(RegisterProperty(entityType, property));
        }