コード例 #1
0
        /// <summary>为时间计算分表分库</summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public virtual ShardModel Get(DateTime time)
        {
            var fi = Field;

            if (fi == null)
            {
                throw new XCodeException("分表策略要求指定时间字段!");
            }

            if (ConnPolicy.IsNullOrEmpty() && TablePolicy.IsNullOrEmpty())
            {
                return(null);
            }

            var table = fi.Factory.Table;

            var model = new ShardModel();

            if (!ConnPolicy.IsNullOrEmpty())
            {
                model.ConnName = String.Format(ConnPolicy, table.ConnName, time);
            }
            if (!TablePolicy.IsNullOrEmpty())
            {
                model.TableName = String.Format(TablePolicy, table.TableName, time);
            }

            return(model);
        }
コード例 #2
0
        /// <summary>为时间计算分表分库</summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public virtual ShardModel Shard(DateTime time)
        {
            if (time.Year <= 1)
            {
                throw new ArgumentNullException(nameof(time), "分表策略要求指定时间!");
            }

            var fi = GetField();

            if (fi == null)
            {
                throw new XCodeException("分表策略要求指定时间字段!");
            }

            if (ConnPolicy.IsNullOrEmpty() && TablePolicy.IsNullOrEmpty())
            {
                return(null);
            }

            var table = Factory.Table;

            var model = new ShardModel();

            if (!ConnPolicy.IsNullOrEmpty())
            {
                model.ConnName = String.Format(ConnPolicy, table.ConnName, time);
            }
            if (!TablePolicy.IsNullOrEmpty())
            {
                model.TableName = String.Format(TablePolicy, table.TableName, time);
            }

            return(model);
        }