调用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; } } }
标签:配置,SqlServer,SqlSugarScope,static,SqlSugar,sql,new,初始 From: https://www.cnblogs.com/happy555/p/16749166.html