Factorize "get all entities" blocks of code