public void TextDapperContextMul() { //TODO 主从 数据库使用下划线_作为分隔符 DbEntityMap.InitMapCfgs(); //init datasourse IDbDatasource dbDatasource = new DbDataSource(); dbDatasource.Init(new NameValueCollection() { ["aa.dataSource.master_AaCenter.connectionString"] = "Data Source =.; Initial Catalog = AaCenter;User ID = sa; Password = db123;", ["aa.dataSource.master_AaCenter.provider"] = "SqlServer" }); dbDatasource.Init(new NameValueCollection() { ["aa.dataSource.slave_AaCenter.connectionString"] = "Data Source =.; Initial Catalog = AaCenterS1;User ID = sa; Password = db123;", ["aa.dataSource.slave_AaCenter.provider"] = "SqlServer" }); IDapperContext dapperContext = new DapperContext(); IVillageRepository villageRepository = new VillageRepository(dapperContext); IUserInfoRepository userInfoRepository = new UserInfoRepository(dapperContext); DbContextHolder.SetDbSourceMode("slave"); try { var user = userInfoRepository.Count(); var model = villageRepository.Get(new Guid("6D880321-DB17-4B32-9F0A-CE9F3F25AA01")); } catch (Exception ex) { throw ex; } }