2025-04-18 16:35:45 +08:00

41 lines
1.3 KiB
C#

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()
{
//ConnectionString = "Data Source=192.168.50.163;User ID=root;Password=123456;Initial Catalog=GXAssembly;Port=3306", // 替换为你的MySQL连接字符串
ConnectionString= "Data Source=139.224.232.211;User ID=root;Password=doantech123;Initial Catalog=GXAssembly;Port=3308",
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;
}
}