Updated: Jun 3
This blog post demonstrates how to query any component type in a solution.
The two examples used are to query all entities in a solution and all security roles in a solution.
The sample D365 Freelancing solution has three entities, contacts, accounts and custom entities. Contact and account are out-of-the-box entities and the custom entity is, surprisingly :), a custom entity. The D365 Freelancing solution also has the out of the box Sales Manager role in it.
The fetch XML queries the Solution Component entity. Linking to the Solution entity so we can filter by the solution name and also linking to the Entity entity so we can get metadata details regarding each entity in the solution. Any component in a solution can be found this way and is demonstrated with a second Fetch XML query displaying all Security Roles in a solution. Simply create a linked entity to the component to query and link on the Solution Component objected and the actual component's primary id (entityid and roleid in these examples).