SqlSugar初始配置
调用SqlSugar访问数据库
public class SqlsugarDbContext { private static readonly SqlSugarScope _client; static SqlsugarDbContext() { var config = new ConfigurationBuilder() .Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true }) .Build(); _client = new SqlSugarScope(new ConnectionConfig { ConnectionString=config.GetConnectionString("SqlServer"), DbType = DbType.SqlServer,//数据库类型 IsAutoCloseConnection = true //不设成true要手动close }, db => { //(A)全局生效配置点 //调试SQL事件,可以删掉 db.Aop.OnLogExecuting = (sql, pars) => { //Console.WriteLine(sql);//输出sql,查看执行sql //5.0.8.2 获取无参数化 SQL //UtilMethods.GetSqlString(DbType.SqlServer,sql,pars) }; } ); } public static SqlSugarScope DbClient { get { return _client; } } }