Esempio n. 1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="type">映射类型</param>
        /// <param name="tbName">表名</param>
        /// <param name="cacheType">表数据缓存方式</param>
        /// <param name="separateType">数据库表拆分方式</param>
        /// <param name="createSql">创建表的sql语句</param>
        /// <param name="separateFieldName">数据表拆分字段</param>
        /// <param name="separateIDHashNum"></param>
        /// <param name="cacheSeconds">是否缓存</param>
        public DBTable(Type type, string tbName, DBTableAttribute attr)
        {
            this.MapType      = type;
            this.AliasName    = type.Name;
            this.Name         = tbName;
            this.CacheType    = attr.CacheType;
            this.SeparateType = attr.SeparateType;

            this.CreateSql = attr.CreateSql;
            if (this.SeparateType != SeparateType.None && string.IsNullOrWhiteSpace(this.CreateSql))
            {
                throw new MyDBException(string.Format("表{0}没有配置创建SQL语句", tbName));
            }
            this.CacheSeconds = attr.CacheSeconds;

            PrimaryKey = new List <DBPrimaryKey>();
            ColumnList = new List <DBColumn>();

            //初始化字段列表
            GetFieldList(type);

            if (PrimaryKey.Count == 0)
            {
                throw new Exception(string.Format("表{0}未映射主键", this.Name));
            }
            if (PrimaryKey.Count > 1 && PrimaryKey[0].DBPrimaryType == DBPrimaryType.Identity)
            {
                throw new Exception(string.Format("表{0}联合主键不支持自增长", this.Name));
            }
            if (PrimaryKey.Count > 1 && this.SeparateType != DBFrame.SeparateType.None)
            {
                throw new Exception(string.Format("表{0}联合主键不支持表拆分", this.Name));
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="name">数据库表名称</param>
 /// <param name="cacheType">数据缓存方式</param>
 /// <param name="cacheSeconds">该数据对象缓存时间(秒数), 默认为10分钟</param>
 /// <param name="separateType">表数据拆分方式</param>
 public DBTableAttribute(string name, CacheType cacheType, int cacheSeconds, SeparateType separateType, string createSql)
 {
     Name           = name;
     this.CacheType = cacheType;
     CacheSeconds   = cacheSeconds;
     SeparateType   = separateType;
     this.CreateSql = createSql;
 }
Esempio n. 3
0
        /// <summary>
        /// 获取表拆分的表名
        /// </summary>
        /// <param name="table"></param>
        /// <param name="sType"></param>
        /// <param name="date"></param>
        /// <param name="sign"></param>
        /// <returns></returns>
        private static string GetFormatTableName(DBMap.DBTable table, SeparateType sType, DateTime date)
        {
            switch (sType)
            {
            case SeparateType.Year:
                return(string.Format("{0}_{1}", table.Name, date.Year));

            case SeparateType.JiDu:
                return(string.Format("{0}_{1}", table.Name, GetJiDu(date)));

            case SeparateType.Mouth:
                return(string.Format("{0}_{1}", table.Name, date.ToString("yyyyMM")));

            case SeparateType.Day:
                return(string.Format("{0}_{1}", table.Name, date.ToString("yyyyMMdd")));
            }
            return(table.Name);
        }
Esempio n. 4
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="name">数据库表名称</param>
 /// <param name="separateType">表数据拆分方式</param>
 public DBTableAttribute(string name, SeparateType separateType, string createSql)
     : this(name, CacheType.None, 10, separateType, createSql)
 {
 }