Esempio n. 1
0
        public static Type GetPropType <T>(string propName)
        {
            Type DefaultType = typeof(string);
            Type result      = typeof(string);
            Type entityType  = typeof(T);
            var  map         = MappingResolver.GetEntityMap(entityType);

            if (map != null)
            {
                var cmi = map.PropertyMaps.FirstOrDefault(e => e.PropertyName == propName);
                if (cmi != null)
                {
                    result = cmi.PropertyType;
                }
            }
            else
            {
                var pInfo = entityType.GetProperty(propName, BindFlags);
                result = pInfo == null ? DefaultType : pInfo.PropertyType;
            }
            if (result.IsEnum)
            {
                result = Enum.GetUnderlyingType(result);
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取实体的主键字段
        /// </summary>
        /// <param name="entityType">实体类型</param>
        /// <returns>主键字段</returns>
        public static string GetPrimaryKeyField(Type entityType)
        {
            var map = MappingResolver.GetEntityMap(entityType);

            if (map != null)
            {
                var colinfo = map.KeyMaps.First();
                if (colinfo == null)
                {
                    throw new ArgumentException(string.Format("实体{0}不存在主键字段", entityType.FullName));
                }
                return(colinfo.PropertyName);
            }
            else
            {
                throw new ArgumentException(string.Format("实体{0}不存在", entityType.FullName));
            }
        }