public function count()
    {
        try {
            $originalQuery = $this->queryBuilder->getQuery();
            $dqlQuery = clone $originalQuery;
            $dqlQuery->setParameters($originalQuery->getParameters());
            $dqlQuery->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]);
            $offset = $dqlQuery->getFirstResult();
            $limit = $dqlQuery->getMaxResults();
            if ($offset !== null) {
                $dqlQuery->setFirstResult(null);
            }
            $numberOfResults = (int)$dqlQuery->getSingleScalarResult();
            if ($offset !== null) {
                $numberOfResults = max(0, $numberOfResults - $offset);
            }
            if ($limit !== null) {
                $numberOfResults = min($numberOfResults, $limit);
            }
            return $numberOfResults;
        } catch (\Doctrine\ORM\ORMException $ormException) {
            $message = $this->throwableStorage->logThrowable($ormException);
            $this->logger->error($message, LogEnvironment::fromMethodName(__METHOD__));
            return 0;
        } catch (\PDOException $pdoException) {
            throw new Exception\DatabaseConnectionException($pdoException->getMessage(), $pdoException->getCode());
        }
    }