项目重命名
This commit is contained in:
26
MesETL.Test/TenantDbHelper.cs
Normal file
26
MesETL.Test/TenantDbHelper.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
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)}'值的对象");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user