Extension methods cannot be dynamically dispatched. So call it without extension method syntax:
static IEnumerable<T> ExecuteQuery<T>(string sql, dynamic param, string connStr)
where T : BaseModel
{
using (var conn = DataAccessHelpers.GetOpenConnection(connStr))
{
return SqlMapper.Query(conn, sql, param).ToList<T>();
}
}
Also you have useless logging which creates multiple log entries for single error, and useless connection disposing (it is done automatically by using block).
Tips for exception handling:
- Handle exception and log it
- Wrap exception in high-level exception and throw that wrapper (caller will handle that high-level exception, or will also wrap it)
- Do not catch exception (caller will do first or second option)