I expect/hope we can move this stuff into InternalEntityFactory but let's not worry about it in this pull request.