You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Ems.CollectService.Common;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Configuration;
namespace Ems.CollectService.SqlSugarCore
{
public class SqlSugarHelper //不能是泛型类
{
//private static string ConnectionString = "Data Source=nyfw-m.db.sfcloud.local;Port=3306;Initial Catalog=sfemsrefactor;uid=highwayiot; pwd=Administrator@;min pool size=1;SslMode=none;Charset=utf8";
//private static string ConnectionString = "Data Source=43.143.98.48;Port=3306;Initial Catalog=hw_ems;uid=root; pwd=yq@123456;min pool size=1;SslMode=none;Charset=utf8";
private static IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("App.json").Build();
//用单例模式
public static SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()
{
ConnectionString = _configuration.GetValue<string>("SystemConfig:mysqlConnStr"),//连接符字串
DbType = DbType.MySql,//数据库类型
IsAutoCloseConnection = true //不设成true要手动close
},
db => {
//(A)全局生效配置点一般AOP和程序启动的配置扔这里面 ,所有上下文生效
//调试SQL事件可以删掉
db.Aop.OnLogExecuting = (sql, pars) =>
{
//Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响
//获取原生SQL推荐 5.1.4.63 性能OK
//UtilMethods.GetNativeSql(sql,pars)
//获取无参数化SQL 对性能有影响特别大的SQL参数多的调试使用
//UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)
};
//多个配置就写下面
//db.Ado.IsDisableMasterSlaveSeparation=true;
//注意多租户 有几个设置几个
//db.GetConnection(i).Aop
});
}
}