2025迁移版本,多项规则修改
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
namespace MesETL.App.Options;
|
||||
|
||||
/// <summary>
|
||||
/// 多租户分库配置
|
||||
/// </summary>
|
||||
public class TenantDbOptions
|
||||
{
|
||||
public string? TenantKey { get; set; }
|
||||
@@ -16,8 +19,21 @@ public class TenantDbOptions
|
||||
// DbList.ForEach(pair => dictionary.Add(pair.Value, pair.Key));
|
||||
// 注意配置顺序
|
||||
if(DbGroup is null) throw new ApplicationException("分库配置中没有发现任何数据库");
|
||||
var dbName = DbGroup.Cast<KeyValuePair<string, int>?>()
|
||||
.FirstOrDefault(pair => pair?.Value != null && pair.Value.Value > tenantKeyValue)!.Value.Key;
|
||||
|
||||
#region 性能较低,不使用
|
||||
|
||||
// var dbName = DbGroup.Cast<KeyValuePair<string, int>?>()
|
||||
// .FirstOrDefault(pair => pair?.Value != null && pair.Value.Value > tenantKeyValue)!.Value.Key;
|
||||
|
||||
#endregion
|
||||
|
||||
string? dbName = null;
|
||||
foreach (var (key, value) in DbGroup)
|
||||
{
|
||||
if (value > tenantKeyValue)
|
||||
dbName = key;
|
||||
}
|
||||
|
||||
return dbName ??
|
||||
throw new ArgumentOutOfRangeException(nameof(tenantKeyValue),
|
||||
$"分库配置中没有任何符合'{nameof(tenantKeyValue)}'值的数据库");
|
||||
|
Reference in New Issue
Block a user