.net 6web api注册sqlsugar全局引用

官方设置文档:https://www.donet5.com/Doc/10/2251
打开Startup.cs配置下面代码

//注入 ORM
builder.Services.AddSqlSugar(new IocConfig()
{
    
    
    ConnectionString = builder.Configuration.GetConnectionString("DbConnectionString"), //数据库连接串
    DbType = IocDbType.MySql,   //数据库类型
    IsAutoCloseConnection = true//自动释放
});

在这里插入图片描述

记得在appsettings.json配置数据库连接字符串

  "ConnectionStrings": {
    
    
    "DbConnectionString": "server=localhost;port=3306;Database=ningblog;Uid=root;Pwd=123456;SslMode=none"
  },

在这里插入图片描述

然后我们就可以在页面上使用了
在这里插入图片描述
**

DbScoped.Sugar 非线程安全
DbScoped.SugarScope 线程安全

**

猜你喜欢

转载自blog.csdn.net/weixin_44442366/article/details/126319089
今日推荐