/// <summary> /// 是否启用删除 /// </summary> /// <param name="databaseName"></param> /// <returns></returns> public bool EnableSoftDelete(string databaseName) { var dataBaseConfiguration = DataBaseConfigurations.Find(m => m.DataBaseName == databaseName); if (dataBaseConfiguration == null) { throw new ArgumentException($"数据库:{databaseName} 未配置!查找不到数据库信息"); } return(!dataBaseConfiguration.DisableSoftDelete); }
/// <summary> /// 根据数据库名称 获取数据库连接 /// </summary> /// <param name="databaseName">数据库名称</param> /// <returns>数据库连接字符串</returns> public string MasterDataBaseConnectionString(string databaseName) { var dataBaseConfiguration = DataBaseConfigurations.Find(m => m.DataBaseName == databaseName); if (dataBaseConfiguration == null) { throw new ArgumentException($"数据库:{databaseName} 主库连接未配置!"); } return(dataBaseConfiguration.MasterDataBaseConnectionString); }
/// <summary> /// 根据数据库名称 获取从库数据库连接 /// </summary> /// <param name="databaseName">数据库名称</param> /// <returns>数据库连接字符串</returns> public string SlaveDataBaseConnectionString(string databaseName) { var dataBaseConfiguration = DataBaseConfigurations.Find(m => m.DataBaseName == databaseName); if (dataBaseConfiguration == null) { throw new ArgumentException($"数据库:{databaseName} 从库连接未配置!"); } //随机一个从库连接 var index = Rd.Next(0, dataBaseConfiguration.SlaveDataBaseConnectionStrings.Count - 1); return(dataBaseConfiguration.SlaveDataBaseConnectionStrings[index]); }