😎fix(初始化): 在表结构初始化前先删除视图,防止视图影响表同步
This commit is contained in:
parent
a3b11ae089
commit
7d51d1c521
@ -400,6 +400,15 @@ public static class SqlSugarSetup
|
|||||||
else
|
else
|
||||||
entityTypes = entityTypes.Where(u => u.GetCustomAttribute<TenantAttribute>()?.configId.ToString() == config.ConfigId.ToString()).ToList(); // 自定义的库
|
entityTypes = entityTypes.Where(u => u.GetCustomAttribute<TenantAttribute>()?.configId.ToString() == config.ConfigId.ToString()).ToList(); // 自定义的库
|
||||||
|
|
||||||
|
// 删除视图再初始化表结构,防止因为视图导致无法同步表结构
|
||||||
|
var viewTypeList = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarView)))).ToList();
|
||||||
|
foreach (var viewType in viewTypeList)
|
||||||
|
{
|
||||||
|
var entityInfo = dbProvider.EntityMaintenance.GetEntityInfo(viewType) ?? throw new Exception("获取视图实体配置有误");
|
||||||
|
if (dbProvider.DbMaintenance.GetViewInfoList(false).Any(it => it.Name.EqualIgnoreCase(entityInfo.DbTableName)))
|
||||||
|
dbProvider.DbMaintenance.DropView(entityInfo.DbTableName);
|
||||||
|
}
|
||||||
|
|
||||||
int taskIndex = 0, size = entityTypes.Count;
|
int taskIndex = 0, size = entityTypes.Count;
|
||||||
var taskList = entityTypes.Select(entityType => Task.Run(() =>
|
var taskList = entityTypes.Select(entityType => Task.Run(() =>
|
||||||
{
|
{
|
||||||
@ -572,7 +581,7 @@ public static class SqlSugarSetup
|
|||||||
var entityInfo = dbProvider.EntityMaintenance.GetEntityInfo(viewType) ?? throw new Exception("获取视图实体配置有误");
|
var entityInfo = dbProvider.EntityMaintenance.GetEntityInfo(viewType) ?? throw new Exception("获取视图实体配置有误");
|
||||||
|
|
||||||
// 如果视图存在,则删除视图
|
// 如果视图存在,则删除视图
|
||||||
if (dbProvider.DbMaintenance.GetViewInfoList().Any(it => it.Name.EqualIgnoreCase(entityInfo.DbTableName)))
|
if (dbProvider.DbMaintenance.GetViewInfoList(false).Any(it => it.Name.EqualIgnoreCase(entityInfo.DbTableName)))
|
||||||
dbProvider.DbMaintenance.DropView(entityInfo.DbTableName);
|
dbProvider.DbMaintenance.DropView(entityInfo.DbTableName);
|
||||||
|
|
||||||
// 获取初始化视图查询SQL
|
// 获取初始化视图查询SQL
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user