| | |
| | | db.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | //判断是否开启redis设置二级缓存方式 |
| | | // DataInfoCacheService = new SqlSugarRedisCache(), |
| | | DataInfoCacheService = new SqlSugarRedisCache(), |
| | | //模型定义为 int?号时自动为可空 |
| | | EntityService = (c, p) => |
| | | { |
| | |
| | | /// <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(); |
| | |
| | | _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创建表 |
| | | } |
| | | } |