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)); }
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); }
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)); } }
/// <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)); }
public TgBellhop Fork() => new TgBellhop(ConnectionPool, CurrentConnection.Get());
public void SetSession(Func <Session, Session> func) => CurrentConnection.Get().Session.SetWith(func);