Exemplo n.º 1
0
 /// <summary>
 /// 获得数据库连接
 /// </summary>
 /// <returns></returns>
 public IDbConnection GetConnection(SourcePointEnum sourcePointEnum, int slaveId)
 {
     try
     {
         if (sourcePointEnum == SourcePointEnum.Master)
         {
             //主库
             return(new MySqlConnection(ConfigHelper.MasterConnectionString));
         }
         else
         {
             //从库
             return(new MySqlConnection(ConfigHelper.SlaveConnectionString[slaveId > 0 ? slaveId - 1 : 0]));
         }
     }
     catch
     {
         throw;
     }
 }
Exemplo n.º 2
0
 public DatabaseContext(SourcePointEnum source, int SlaveId)
 {
     this.Source  = source;
     this.SlaveId = SlaveId;
 }