2025-04-06 13:36:16 +08:00
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace linesider_screen_bankend.Services.SQLHepler
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class SqlSugarHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly Lazy<SqlSugarScope> _db = new Lazy<SqlSugarScope>(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var config = new ConnectionConfig()
|
|
|
|
|
|
{
|
2025-04-08 16:23:05 +08:00
|
|
|
|
ConnectionString = "Data Source=139.224.232.211;User ID=root;Password=doantech123;Initial Catalog=GXAssembly;Port=3308", // 替换为你的MySQL连接字符串
|
2025-04-06 13:36:16 +08:00
|
|
|
|
DbType = DbType.MySql, // 数据库类型设置为MySQL
|
|
|
|
|
|
IsAutoCloseConnection = true, // 自动释放
|
|
|
|
|
|
InitKeyType = InitKeyType.Attribute // 从实体特性读取主键信息
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var scope = new SqlSugarScope(config, db =>
|
|
|
|
|
|
{
|
|
|
|
|
|
// 配置AOP
|
|
|
|
|
|
db.Aop.OnLogExecuting = (sql, pars) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(sql); // 输出SQL
|
|
|
|
|
|
// 可以在这里记录日志
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 配置更多选项
|
|
|
|
|
|
db.Ado.CommandTimeOut = 30;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return scope;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
public static SqlSugarScope Db => _db.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|