Exemplo n.º 1
0
        public static async Task <BaseSqlResponse <IEnumerable <T> > > SafeQueryAsync <T>(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null,
                                                                                          bool buffered = true, int?commandTimeout = null, CommandType?commandType = null)
        {
            var response = new BaseSqlResponse <IEnumerable <T> >();

            try
            {
                commandTimeout   = commandTimeout ?? DapperDb.DbTimeout;
                response.Content = await cnn.QueryAsync <T>(sql, param, transaction, commandTimeout, commandType);
            }
            catch (Exception e)
            {
                LogToSql(cnn, sql, param, e);
            }
            return(response);
        }
Exemplo n.º 2
0
        public static async Task <BaseSqlResponse> SafeExecuteAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null,
                                                                    bool buffered = true, int?commandTimeout = null, CommandType?commandType = null)
        {
            var response = new BaseSqlResponse();

            try
            {
                commandTimeout = commandTimeout ?? DapperDb.DbTimeout;
                await cnn.ExecuteAsync(sql, param, commandType : commandType, commandTimeout : commandTimeout);
            }
            catch (Exception e)
            {
                try
                {
                    LogToSql(cnn, sql, param, e);
                }
                catch (Exception)
                {
                    //Add to other log target
                }
                response.Exception = e;
            }
            return(response);
        }