添加数据分库;
修复taskManager中异步方法没有正常等待的错误; 删除无用的异常捕获;
This commit is contained in:
23
ConsoleApp2/Options/TenantDbOptions.cs
Normal file
23
ConsoleApp2/Options/TenantDbOptions.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace ConsoleApp2.Options;
|
||||
|
||||
public class TenantDbOptions
|
||||
{
|
||||
public string TenantKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Key-Value: {DbName}-{TenantKeyLessThan}
|
||||
/// </summary>
|
||||
public Dictionary<string, int> DbList { get; set; }
|
||||
|
||||
public 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