private static string GetTableName()
        {
            Type   type      = typeof(T);
            string tableName = null;

            if (type.IsDefined(typeof(EntityMappingAttribute), true))
            {
                EntityMappingAttribute attributeType = type.GetCustomAttribute(typeof(EntityMappingAttribute)) as EntityMappingAttribute;
                tableName = attributeType.DALName;
            }
            else
            {
                tableName = type.Name;
            }
            return(tableName);
        }
Example #2
0
        /// <summary>
        ///  根据传入的实体对象获得数据库架构级表的映射名称
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static string GetMapping(Type t)
        {
            string   tableName             = string.Empty;
            TypeInfo typeInfo              = t.GetTypeInfo();
            EntityMappingAttribute mapping = typeInfo.GetCustomAttribute(typeof(EntityMappingAttribute)) as EntityMappingAttribute;

            if (mapping != null)
            {
                tableName = mapping.Name;
                if (!string.IsNullOrEmpty(mapping.Schema))
                {
                    tableName = mapping.Schema + "." + tableName;
                }
            }
            else
            {
                throw new NotSupportedException("在表连接实体上找不到特性 EntityMappingAttribute ,请确认数据库实体模型");
            }

            return(tableName);
        }