.net 6 web api registration sqlsugar global reference

Official setting document: https://www.donet5.com/Doc/10/2251
Open Startup.cs to configure the following code

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

insert image description here

Remember to configure the database connection string in appsettings.json

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

insert image description here

Then we can use it on the page
insert image description here
**

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

**

Guess you like

Origin blog.csdn.net/weixin_44442366/article/details/126319089