public static IEnumerable <T> Query <T>(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int?commandTimeout = null, CommandType?commandType = null) { var guid = DiagnosticExtension.Write(sql, param, cnn); try { IEnumerable <T> result; if (UseLocalParser) { var reader = //cnn.ExecuteReader(sql, param, transaction, commandTimeout, commandType);//用这句 日志有重复性问题 Dapper.SqlMapper.ExecuteReader(cnn, sql, param, transaction, commandTimeout, commandType); result = reader.ReadGrid <T>().ToList(); reader.Close(); } else { result = Dapper.SqlMapper.Query <T>(cnn, sql, param, transaction, buffered, commandTimeout, commandType); } DiagnosticExtension.WriteAfter(guid); return(result); } catch (Exception ex) { DiagnosticExtension.WriteError(guid, ex); throw; } }
public static async Task <IEnumerable <T> > QueryAsync <T>(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int?commandTimeout = null, CommandType?commandType = null) { var guid = DiagnosticExtension.Write(sql, param, cnn); try { IEnumerable <T> result; if (UseLocalParser) { var reader = //await cnn.ExecuteReaderAsync(sql, param, transaction, commandTimeout, commandType); await Dapper.SqlMapper.ExecuteReaderAsync(cnn, sql, param, transaction, commandTimeout, commandType); result = reader.ReadGrid <T>().ToList(); reader.Close(); } else { result = await Dapper.SqlMapper.QueryAsync <T>(cnn, sql, param, transaction, commandTimeout, commandType); } DiagnosticExtension.WriteAfter(guid); return(result); } catch (Exception ex) { DiagnosticExtension.WriteError(guid, ex); throw; } }
public static IDataReader ExecuteReader(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int?commandTimeout = null, CommandType?commandType = null) { var guid = DiagnosticExtension.Write(sql, param, cnn); try { var result = Dapper.SqlMapper.ExecuteReader(cnn, sql, param, transaction, commandTimeout, commandType); DiagnosticExtension.WriteAfter(guid); return(result); } catch (Exception ex) { DiagnosticExtension.WriteError(guid, ex); throw; } }
public static async Task <T> QuerySingleAsync <T>(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int?commandTimeout = null, CommandType?commandType = null) { var guid = DiagnosticExtension.Write(sql, param, cnn); try { var result = await Dapper.SqlMapper.QuerySingleAsync <T>(cnn, sql, param, transaction, commandTimeout, commandType); DiagnosticExtension.WriteAfter(guid); return(result); } catch (Exception ex) { DiagnosticExtension.WriteError(guid, ex); throw; } }