From bdfd7fef242a519aac505d83591e11e2aa75f75e Mon Sep 17 00:00:00 2001 From: liaoxujun@qq.com <liaoxujun@qq.com> Date: 星期二, 01 八月 2023 17:14:28 +0800 Subject: [PATCH] 完成租户用户同一api登录,新增加租户表,租户关联表, 员工表增加TenderID 字段 需要增加表只需要将 appset codefirst设置为true 运行将自动更新表结构 --- DocumentServiceAPI.Core/DbContext.cs | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/DocumentServiceAPI.Core/DbContext.cs b/DocumentServiceAPI.Core/DbContext.cs index 2aaa3fd..069d96f 100644 --- a/DocumentServiceAPI.Core/DbContext.cs +++ b/DocumentServiceAPI.Core/DbContext.cs @@ -92,11 +92,12 @@ /// <param name="ModeProjectName"></param> public static void DbCodeFirst(this IApplicationBuilder app, string ModeProjectName, string? Modenamespace = null, string? ConfigId = null) { - var ddb= App.GetService<ISqlSugarClient>(); + var _db = app.ApplicationServices.GetService<ISqlSugarClient>(); //鍒囨崲鏁版嵁搴� if (!string.IsNullOrEmpty(ConfigId)) _db.AsTenant().ChangeDatabase(ConfigId); + //寤哄簱 _db.DbMaintenance.CreateDatabase(); Type[]? types = UtilityFun.GetAllAssembly().Where(x => x.FullName.Contains(ModeProjectName + ",")).FirstOrDefault()?.GetTypes().WhereIF(!string.IsNullOrEmpty(Modenamespace), name => name.FullName.Contains(Modenamespace + ".")).ToArray().Where(x => x.IsSubclassOf(typeof(BaseModel))).ToArray(); @@ -104,4 +105,14 @@ _db.CodeFirst.InitTables(types);//鏍规嵁types鍒涘缓琛� } + public static void DbCodeFirst(this IApplicationBuilder app, Type Obj, string? ConfigId = null) + { + var _db = app.ApplicationServices.GetService<ISqlSugarClient>(); + //鍒囨崲鏁版嵁搴� + if (!string.IsNullOrEmpty(ConfigId)) + _db.AsTenant().ChangeDatabase(ConfigId); + //寤哄簱 + _db.DbMaintenance.CreateDatabase(); + _db.CodeFirst.InitTables(Obj);//鏍规嵁types鍒涘缓琛� + } } -- Gitblit v1.9.1