#271 cast count query converted to use ORM