2025-10-04 18:42:12 +08:00
|
|
|
using DMS.Application.Configurations;
|
2025-07-18 19:56:00 +08:00
|
|
|
using SqlSugar;
|
2025-05-29 08:58:58 +08:00
|
|
|
|
2025-07-19 09:25:01 +08:00
|
|
|
namespace DMS.Infrastructure.Data;
|
2025-06-23 17:01:06 +08:00
|
|
|
|
2025-07-19 22:29:50 +08:00
|
|
|
public class SqlSugarDbContext
|
2025-05-29 08:58:58 +08:00
|
|
|
{
|
2025-10-03 00:05:17 +08:00
|
|
|
private readonly AppSettings _settings;
|
2025-07-19 09:25:01 +08:00
|
|
|
|
2025-07-19 22:29:50 +08:00
|
|
|
public SqlSugarDbContext(AppSettings settings)
|
2025-06-23 17:01:06 +08:00
|
|
|
{
|
2025-10-03 00:05:17 +08:00
|
|
|
_settings = settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SqlSugarClient GetInstance()
|
|
|
|
|
{
|
|
|
|
|
var connectionString = _settings.ToConnectionString();
|
2025-10-04 18:42:12 +08:00
|
|
|
var dbType = (SqlSugar.DbType)Enum.Parse(typeof(SqlSugar.DbType), _settings.Db.DbType);
|
2025-07-06 11:09:57 +08:00
|
|
|
|
2025-10-03 00:05:17 +08:00
|
|
|
return new SqlSugarClient(new ConnectionConfig
|
2025-05-29 08:58:58 +08:00
|
|
|
{
|
2025-06-25 22:33:57 +08:00
|
|
|
ConnectionString = connectionString,
|
2025-07-19 09:25:01 +08:00
|
|
|
DbType = dbType,
|
2025-06-25 22:33:57 +08:00
|
|
|
IsAutoCloseConnection = true,
|
|
|
|
|
InitKeyType = InitKeyType.Attribute
|
|
|
|
|
});
|
2025-07-19 09:25:01 +08:00
|
|
|
}
|
2025-06-23 17:01:06 +08:00
|
|
|
}
|