abp 动态切换连接字符串并执行sql
仓储层
1 // 创建 DbContextOptionsBuilder 实例 2 var optionsBuilder = new DbContextOptionsBuilder<MicroServiceDbContext>(); 3 4 // 设置连接字符串 5 optionsBuilder.UseSqlServer("User ID=sa;Initial Catalog=;Data Source=;Password=;Connection Lifetime=60000;Encrypt=false;"); 6 7 // 使用 optionsBuilder 构建 DbContext 实例并进行数据库操作 8 using var dbContext = new MicroServiceDbContext(optionsBuilder.Options); 9 10 var sql = $"INSERT INTO [dbo]......"; 11 var formattableSql = FormattableStringFactory.Create(sql); 12 dbContext.Database.ExecuteSql(formattableSql);
标签:abp,var,optionsBuilder,sql,字符串,连接 From: https://www.cnblogs.com/feigao/p/17491643.html