26 lines
995 B
C#
26 lines
995 B
C#
namespace TestProject1;
|
|
|
|
public static class TenantDbHelper
|
|
{
|
|
/// <summary>
|
|
/// Key-Value: {DbName}-{TenantKeyLessThan}
|
|
/// </summary>
|
|
public static Dictionary<string, int> DbList { get; set; } = new Dictionary<string, int>
|
|
{
|
|
{ "cferp_test_1", 1000 },
|
|
{ "cferp_test_2", 2000 },
|
|
{ "cferp_test_3", int.MaxValue },
|
|
};
|
|
|
|
public static string GetDbNameByTenantKeyValue(int tenantKeyValue)
|
|
{
|
|
// var dictionary = new SortedDictionary<int, string>();
|
|
// DbList.ForEach(pair => dictionary.Add(pair.Value, pair.Key));
|
|
// 注意配置顺序
|
|
var dbName = DbList.Cast<KeyValuePair<string, int>?>()
|
|
.FirstOrDefault(pair => pair?.Value != null && pair.Value.Value > tenantKeyValue)!.Value.Key;
|
|
return dbName ??
|
|
throw new ArgumentOutOfRangeException(nameof(tenantKeyValue),
|
|
$"已配置的数据库中没有任何符合'{nameof(tenantKeyValue)}'值的对象");
|
|
}
|
|
} |