add 后台服务 和 部署sql 等
This commit is contained in:
50
Ewide.Nbzs.BackWorkerService/DbManage.cs
Normal file
50
Ewide.Nbzs.BackWorkerService/DbManage.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Furion;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Ewide.Nbzs.BackWorkerService
|
||||
{
|
||||
public class MutiDBConnectionString
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string ConnectionString { get; set; }
|
||||
public DbType DbType { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public string ProviderName { get; set; }
|
||||
}
|
||||
public class DbManage
|
||||
{
|
||||
private static List<MutiDBConnectionString> GetConnectionStrings()
|
||||
{
|
||||
var list = App.GetConfig<List<MutiDBConnectionString>>("DataBaseConnectionStrings");
|
||||
return list.Where(p => p.Enabled).ToList();
|
||||
}
|
||||
|
||||
private static SqlSugarClient GetDbClient()
|
||||
{
|
||||
List<ConnectionConfig> connectConfigList = new();
|
||||
GetConnectionStrings().ForEach(p =>
|
||||
{
|
||||
connectConfigList.Add(new ConnectionConfig
|
||||
{
|
||||
ConfigId = p.Id,
|
||||
ConnectionString = p.ConnectionString,
|
||||
DbType = p.DbType,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute
|
||||
});
|
||||
});
|
||||
var db = new SqlSugarClient(connectConfigList);
|
||||
return db;
|
||||
}
|
||||
public static SqlSugarProvider GetConnection(string id)
|
||||
{
|
||||
return GetDbClient().GetConnection(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user