diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/AppService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/AppService.cs index 47b938e1..9c513cd0 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/AppService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/AppService.cs @@ -12,29 +12,34 @@ class AppService : IApp { private const string AppServiceGetAppsByRoleIdCacheKey = "AppService-GetAppsByRoleId"; - private IDatabase Database { get; } + private IDBManager DBManager { get; } - public AppService(IDatabase db) + public AppService(IDBManager db) { - Database = db; + DBManager = db; } - public List GetAppsByRoleId(string? roleId) => CacheManager.GetOrAdd($"{AppServiceGetAppsByRoleIdCacheKey}-{roleId}", entry => Database.Fetch("select AppID from RoleApp where RoleID = @0", roleId)); + public List GetAppsByRoleId(string? roleId) => CacheManager.GetOrAdd($"{AppServiceGetAppsByRoleIdCacheKey}-{roleId}", entry => + { + using var db = DBManager.Create(); + return db.Fetch("select AppID from RoleApp where RoleID = @0", roleId); + }); public bool SaveAppsByRoleId(string? roleId, IEnumerable appIds) { var ret = false; + using var db = DBManager.Create(); try { - Database.BeginTransaction(); - Database.Execute("delete from RoleApp where RoleID = @0", roleId); - Database.InsertBatch("RoleApp", appIds.Select(g => new { AppID = g, RoleID = roleId })); - Database.CompleteTransaction(); + db.BeginTransaction(); + db.Execute("delete from RoleApp where RoleID = @0", roleId); + db.InsertBatch("RoleApp", appIds.Select(g => new { AppID = g, RoleID = roleId })); + db.CompleteTransaction(); ret = true; } catch (Exception) { - Database.AbortTransaction(); + db.AbortTransaction(); throw; } if (ret) diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DBManagerService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DBManagerService.cs index 5cc5f760..f14ad0e9 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DBManagerService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DBManagerService.cs @@ -36,7 +36,7 @@ internal class DBManagerService : IDBManager /// 连接字符串键值 /// /// - public IDatabase Create(string? connectionName = "client", bool keepAlive = false) + public IDatabase Create(string? connectionName = "ba", bool keepAlive = false) { var conn = Configuration.GetConnectionString(connectionName) ?? throw new ArgumentNullException(nameof(connectionName));