/// <summary> /// 获取分区数据库名称 /// </summary> /// <param name="strategy">分区策略</param> /// <param name="logicalDbName">逻辑数据库名</param> /// <returns>分区数据库名称</returns> public List <string> GetShardingDBNames(DatabaseShardingStrategy strategy, string logicalDbName) { var dbNames = new List <string>(); strategy.PostFixValueList.ForEach(i => dbNames.Add(string.Format("{0}{1}", logicalDbName, i))); return(dbNames); }
/// <summary> /// 获取单键分库计算器 /// </summary> /// <param name="strategy">数据库Sharding策略</param> /// <returns>分库计算器</returns> public static ISingleKeyDatabaseShardingAlgorithm GetSingKeyShardingAlgorithm(DatabaseShardingStrategy strategy) { ISingleKeyDatabaseShardingAlgorithm algorithm = null; switch (strategy.ShardingType) { case ShardingType.Year: algorithm = new DatabaseShardingYearAlgorithm(); break; case ShardingType.Enum: algorithm = new DatabaseShardingEnumAlgorithm(); break; case ShardingType.Hash: algorithm = new DatabaseShardingHashAlgorithm(strategy.ShardingFactor); break; default: break; } return(algorithm); }