protected function createCountQuery(array $fields = [], array $criteria = [], $distinct = true)
	{
		if ($this->objectManager instanceof \Doctrine\ORM\EntityManager) {
			/** @var \Doctrine\ORM\QueryBuilder $builder */
			$builder = $this->objectManager->createQueryBuilder();
			
			if (empty($fields)) {
				/** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata */
				$classMetadata = $this->objectManager->getClassMetadata($this->className);
				$identifier = $classMetadata->getIdentifierFieldNames()[0];
			} else {
				$identifier = $fields[0]; // Replace with $identifier = implode(', p.', $fields);
			}
			
			$builder->select($distinct ? $builder->expr()->countDistinct('p.' . $identifier) : $builder->expr()->count('p.' . $identifier))
					->from($this->className, 'p');
		} elseif ($this->objectManager instanceof \Doctrine\ODM\MongoDB\DocumentManager) {
			/** @var \Doctrine\ODM\MongoDB\Query\Builder $builder */
			$builder = $this->objectManager->createQueryBuilder($this->className);
			
			if (false === empty($fields) && true === $distinct) {
				$builder->distinct($fields[0]);
			}
			
			$builder->count();
		} else {
			throw new ObjectManagerNotSupportedException(sprintf('Doctrine object manager class "%s" is not supported.', get_class($this->objectManager)));
		}
		
		$this->qbHandler->applyExprFromArray($builder, 'p', $criteria);
		
		return $builder->getQuery();
	}