Example #1
0
 public T Get <T>(int id) where T : class
 {
     if (CurrentTransaction != null)
     {
         return(DbExecProxy <T>((param) => CurrentConnection.Get <T>(id, CurrentTransaction, CommandTimeout), "get by id", null));
     }
     using var connection = GetDbConnection(DataSourceEnum.SLAVE);
     return(DbExecProxy <T>((param) => connection.Get <T>(id, CurrentTransaction, CommandTimeout), "get by id", null));
 }
Example #2
0
        async Task <TgConnection> ChangeConn(Func <TgConnection, Task <TgConnection> > f)
        {
            var oldConn = CurrentConnection.Get();
            var newConn = await f(oldConn);

            CurrentConnection.Set(newConn);
            MirrorUpdates(newConn);
            return(newConn);
        }
Example #3
0
        async Task <T> CallWithReConnect <T>(ITgFunc <T> func)
        {
            try
            {
                var conn = CurrentConnection.Get();
                return(await conn.Transport.Call(func));
            }
            catch (TgTransportException)
            {
                var oldConn = CurrentConnection.Get();
                oldConn.Dispose();

                var conn = await ChangeConn(x => ConnectionPool.ReConnect(x.Config.ThisDc));

                return(await conn.Transport.Call(func));
            }
        }
Example #4
0
 /// <summary>
 /// 根据id获取记录
 /// </summary>
 /// <returns>记录</returns>
 /// <param name="id">id.</param>
 public T GetByKeyID <T>(object id)
     where T : ModelBase
 {
     return(CurrentConnection.Get <T>(id, CurrentTransaction));
 }
Example #5
0
 public TgBellhop Fork() =>
 new TgBellhop(ConnectionPool, CurrentConnection.Get());
Example #6
0
 public void SetSession(Func <Session, Session> func) =>
 CurrentConnection.Get().Session.SetWith(func);