public async Task <IEnumerable <T> > QueryAsync <T>(RequestContext context, DataSourceType sourceType = DataSourceType.Read) { #region Read Cache var cache = CacheManager[context, typeof(IEnumerable <T>)]; if (cache != null) { return((IEnumerable <T>)cache); } #endregion IDbConnectionSession session = SessionStore.LocalSession; if (session == null) { session = CreateDbSession(sourceType); } string sqlStr = SqlBuilder.BuildSql(context); try { var result = await session.Connection.QueryAsync <T>(sqlStr, context.DapperDynamicParams, session.DbTransaction); CacheManager[context, typeof(IEnumerable <T>)] = result; return(result); } catch (Exception ex) { throw ex; } finally { if (session.LifeCycle == DbSessionLifeCycle.Transient) { session.CloseConnection(); } } }
public async Task <T> RunAsync <T>(RequestContext context, DataSourceChoice sourceChoice, Func <String, IDbConnectionSession, Task <T> > runSql) { IDbConnectionSession session = SmartSqlMapper.SessionStore.LocalSession; if (session == null) { session = SmartSqlMapper.CreateDbSession(sourceChoice); } string sqlStr = SqlBuilder.BuildSql(context); try { T result = await runSql(sqlStr, session); return(result); } catch (Exception ex) { throw ex; } finally { if (session.LifeCycle == DbSessionLifeCycle.Transient) { session.CloseConnection(); } } }
public IDataReader ExecuteReader(string sqlStr, object reqParams, DataSourceType sourceType = DataSourceType.Read) { IDbConnectionSession session = SessionStore.LocalSession; if (session == null) { session = CreateDbSession(sourceType); } try { var result = session.Connection.ExecuteReader(sqlStr, reqParams); return(result); } catch (Exception ex) { throw ex; } finally { if (session.LifeCycle == DbSessionLifeCycle.Transient) { session.CloseConnection(); } } }
public IEnumerable <dynamic> QueryBySql(String sqlStr, object reqParams, DataSourceType sourceType = DataSourceType.Read) { IDbConnectionSession session = SessionStore.LocalSession; if (session == null) { session = CreateDbSession(sourceType); } try { var result = session.Connection.Query(sqlStr, reqParams, session.DbTransaction); return(result); } catch (Exception ex) { throw ex; } finally { if (session.LifeCycle == DbSessionLifeCycle.Transient) { session.CloseConnection(); } } }
public IEnumerable <T> Query <T>(RequestContext context, DataSourceChoice sourceChoice) { var cache = CacheManager[context, typeof(IEnumerable <T>)]; if (cache != null) { return((IEnumerable <T>)cache); } IDbConnectionSession session = SessionStore.LocalSession; if (session == null) { session = CreateDbSession(sourceChoice); } string sqlStr = SqlBuilder.BuildSql(context); try { var result = session.Connection.Query <T>(sqlStr, context.DapperParameters, session.Transaction); CacheManager[context, typeof(IEnumerable <T>)] = result; return(result); } catch (Exception ex) { throw ex; } finally { if (session.LifeCycle == DbSessionLifeCycle.Transient) { session.CloseConnection(); } } }
public async Task <T> ExecuteAsync <T>(RequestContext context, DataSourceType dataSourceType, Func <string, IDbConnectionSession, Task <T> > executeSql) { IDbConnectionSession session = _baraMapper.SessionStore.LocalSession; if (session == null) { session = _baraMapper.CreateDbSession(dataSourceType); } try { var strSql = _sqlBuilder.BuildSql(context); return(await executeSql(strSql, session)); } catch (Exception ex) { throw ex; } finally { if (session.LifeCycle == DbSessionLifeCycle.Transient) { session.CloseConnection(); } } }
public void CloseConnection() { _connectionSession.CloseConnection(); }