只有在没数据库的情况下才初始化种子
This commit is contained in:
parent
cb7e216b3a
commit
959a2bf642
@ -21,17 +21,23 @@ namespace DHSoftware.Utils
|
||||
EnsureDirectoryExists();
|
||||
using (var db = GetDatabase())
|
||||
{
|
||||
// 创建所有表
|
||||
db.CodeFirst.InitTables(
|
||||
typeof(User),
|
||||
typeof(Role),
|
||||
typeof(Permission),
|
||||
typeof(UserRole),
|
||||
typeof(RolePermission)
|
||||
);
|
||||
// 检查初始化状态(通过检查是否存在系统表)
|
||||
bool isInitialized = db.DbMaintenance.IsAnyTable("RolePermission");
|
||||
|
||||
// 初始化基础数据
|
||||
InitializeSeedData(db);
|
||||
if (!isInitialized)
|
||||
{
|
||||
// 创建所有表
|
||||
db.CodeFirst.InitTables(
|
||||
typeof(User),
|
||||
typeof(Role),
|
||||
typeof(Permission),
|
||||
typeof(UserRole),
|
||||
typeof(RolePermission)
|
||||
);
|
||||
|
||||
// 初始化基础数据
|
||||
InitializeSeedData(db);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user