/// <summary> /// Returns a single entity of type T. /// </summary> /// <typeparam name="T">Type of entity</typeparam> /// <param name="connection">Open SqlConnection</param> /// <param name="adapter">ISqlAdapter for getting the sql statement</param> /// <param name="sql">The sql clause</param> /// <param name="parameters">Parameters of the sql clause</param> /// <param name="transaction">The transaction to run under, null (the default) if none</param> /// <param name="commandTimeout">Number of seconds before command execution timeout</param> /// <param name="fromCache">Cache the query.</param> /// <returns>the entity, else null</returns> private static async Task <T> GetAsync <T>(this IDbConnection connection, ISqlAdapter adapter, string sql, object parameters, IDbTransaction transaction = null, int?commandTimeout = null, bool fromCache = false) where T : class { var type = typeof(T); var tinfo = TableInfoCache(type); var selectSql = adapter.GetQuery(tinfo, sql, fromCache); return((await connection.QueryAsync <T>(selectSql, parameters, transaction, commandTimeout: commandTimeout)).SingleOrDefault()); }