/// <summary> /// 异步执行 /// </summary> /// <typeparam name="TResult">结果类型</typeparam> /// <param name="connectionId">连接ID</param> /// <param name="isClose">是否关闭</param> /// <param name="dbConnection">数据库连接</param> /// <param name="func">函数</param> /// <returns>结果任务</returns> protected async Task <TResult> ExecAsync <TResult>(string connectionId, bool isClose, IDbConnection dbConnection, Func <TResult> func) { return(await Task.Run <TResult>(() => { TResult result = func(); if (isClose) { DbConnectionManager.Release(connectionId, dbConnection); } return result; })); }
/// <summary> /// 异步执行 /// </summary> /// <typeparam name="TResult">结果类型</typeparam> /// <param name="connectionId">连接ID</param> /// <param name="isClose">是否关闭</param> /// <param name="dbConnection">数据库连接</param> /// <param name="func">函数</param> /// <param name="mode">访问模式</param> /// <returns>结果任务</returns> protected async Task <TResult> ExecAsync <TResult>(string connectionId, bool isClose, IDbConnection dbConnection, Func <IDbTransaction, TResult> func, AccessMode mode = AccessMode.MASTER) { var dbTrans = DbConnectionManager.GetDbTransaction(connectionId, this, mode); return(await Task.Run <TResult>(() => { TResult result = func(dbTrans); if (isClose) { DbConnectionManager.Release(connectionId, dbConnection); } return result; })); }
/// <summary> /// 释放连接ID /// </summary> /// <param name="connectionId">连接ID</param> public void Release(string connectionId) => DbConnectionManager.Release(connectionId);