예제 #1
0
        /// <summary>
        /// 根据MyId的主键获取拆分表名
        /// </summary>
        /// <param name="type">对应的数据库映射信息</param>
        /// <param name="myId">MyId主键值</param>
        /// <returns></returns>
        internal static string GetTableName(DBMap.DBTable table, object myId)
        {
            if (table.SeparateType == SeparateType.None)
            {
                return(table.Name);
            }

            return(GetTableName(table, MyIdMake.GetMyIdDate(myId)));
        }
예제 #2
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);
        }
예제 #3
0
        /// <summary>
        /// 根据时间获取对应的拆分表名
        /// </summary>
        /// <param name="table">对应的数据库映射信息</param>
        /// <param name="date">主键时间</param>
        /// <returns>返回拆分的表名</returns>
        internal static string GetTableName(DBMap.DBTable table, DateTime date)
        {
            if (table.SeparateType == SeparateType.None)
            {
                return(table.Name);
            }

            //获取表名
            string tbName = GetFormatTableName(table, table.SeparateType, date);

            if (string.IsNullOrWhiteSpace(tbName))
            {
                return(table.Name);
            }
            if (tbName.Equals(table.Name))
            {
                return(table.Name);
            }

            //判断表是否已存在验证
            ConcurrentBag <string> cb = null;

            if (!_cdCheckDate.TryGetValue(table.MapType.FullName, out cb))
            {
                _cdCheckDate.TryAdd(table.MapType.FullName, cb = new ConcurrentBag <string>());
            }

            //如果不存在,则验证数据库中是否存在该表
            if (!cb.Contains(tbName))
            {
                //验证表在数据库中是否存在
                if (CheckTableAndCreate(table, tbName))
                {
                    cb.Add(tbName);
                }
                else
                {
                    //如果数据库中不存在该分表,则返回默认的表名
                    return(table.Name);
                }
            }
            return(tbName);
        }