Moving database queries to EntityRepository layer.