{ "ConnectionStrings": { "Default": "server=192.168.3.5;Initial Catalog=your_db_name;User=root;Password=111222;port=3306;sslMode=None;" } }
public class DapperMysqlHelper { private readonly int commandTimeout = 30;//设置超时时间5秒 private readonly IConfiguration _configuration; /// <summary> /// 构造方法 /// </summary> /// <param name="options"></param> public DapperMysqlHelper(IConfiguration configuration) { _configuration = configuration; } /// <summary> /// 获取数据库连接对象 /// </summary> /// <returns></returns> public MySqlConnection GetConnection() { return new MySqlConnection(_configuration.GetConnectionString("Default")); } }
Dapper的一个辅助类:DapperMysqlHelper,其它的方法不贴了。
标签:asp,数据库,IConfiguration,readonly,DapperMysqlHelper,core3.1,net,configuration,publ From: https://www.cnblogs.com/subendong/p/16826150.html