Exemplo n.º 1
0
 /// <summary>
 /// Intended for implementing <see cref="Interfaces.ITestableQuery"/> for unit testing, not intended for use on its own
 /// </summary>
 public IEnumerable <dynamic> TestExecuteHelper(IDbConnection connection)
 {
     try
     {
         ResolvedSql = QueryUtil.ResolveSql(Sql, this, out DynamicParameters queryParams);
         return(connection.Query(ResolvedSql, queryParams));
     }
     catch (Exception exc)
     {
         throw new Exception($"Query {GetType().Name} failed: {exc.Message}", exc);
     }
 }
Exemplo n.º 2
0
        public TResult ExecuteSingle(IDbConnection connection)
        {
            ResolvedSql = QueryUtil.ResolveSql(Sql, this, out DynamicParameters queryParams);
            Parameters  = queryParams;

            var stopwatch = Stopwatch.StartNew();

            try
            {
                return(connection.QuerySingle <TResult>(ResolvedSql, queryParams));
            }
            catch (Exception exc)
            {
                throw new QueryException(exc, ResolvedSql, queryParams);
            }
            finally
            {
                stopwatch.Stop();
                OnQueryExecuted(new QueryTrace(ResolvedSql, queryParams, stopwatch.Elapsed));
            }
        }
Exemplo n.º 3
0
        public async Task <IEnumerable <TResult> > ExecuteAsync(IDbConnection connection)
        {
            ResolvedSql = QueryUtil.ResolveSql(Sql, this, out DynamicParameters queryParams);
            Parameters  = queryParams;

            var stopwatch = Stopwatch.StartNew();

            try
            {
                return(await connection.QueryAsync <TResult>(ResolvedSql, queryParams));
            }
            catch (Exception exc)
            {
                throw new QueryException(exc, ResolvedSql, queryParams);
            }
            finally
            {
                stopwatch.Stop();
                var qt = new QueryTrace(ResolvedSql, queryParams, stopwatch.Elapsed);
                OnQueryExecuted(qt);
                await OnQueryExecutedAsync(qt);
            }
        }
Exemplo n.º 4
0
 public string ResolveSql(out DynamicParameters queryParams)
 {
     ResolvedSql = QueryUtil.ResolveSql(Sql, this, out queryParams);
     Parameters  = queryParams;
     return(ResolvedSql);
 }