添加数据分库;

修复taskManager中异步方法没有正常等待的错误;
删除无用的异常捕获;
This commit is contained in:
2024-01-19 11:17:22 +08:00
parent 45ad15a065
commit 8da3110ecd
12 changed files with 94 additions and 61 deletions

View 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)}'值的对象");
}
}