调整初始化租户业务数据Id为空值时自动设置,非空或大于0时按种子设定的Id插入。

This commit is contained in:
9kbx 2024-09-19 14:47:52 +08:00
parent 18a4aea875
commit cbc838fe43

View File

@ -479,7 +479,9 @@ public static class SqlSugarSetup
{
foreach (var sd in seedData)
{
sd.GetType().GetProperty(nameof(EntityBaseId.Id))!.SetValue(sd, ++tenantId);
var id = sd.GetType().GetProperty(nameof(EntityBaseId.Id))!.GetValue(sd, null);
if (id != null && (id.ToString() == "0" || string.IsNullOrWhiteSpace(id.ToString())))
sd.GetType().GetProperty(nameof(EntityBaseId.Id))!.SetValue(sd, ++tenantId);
}
}