Refactoring the extension methods used by the conventions.

Also adding tests for unusual entity types.