Refactoring sql query used in the EntityRepository. Correcting a few issues with the UmbracoObjectTypes extensions.