query entity, count and then action