There are 4 sql statements generated: one for fetching the roles collection (this one has an order by clause) and 3 more, one to fetch all users for each role. None of these has an orderby clause, and thats what I was trying to do.
Here is the method that gets invoked internally in the manager:
protected EntityCollection FetchCollectionWithUsersCollection( RelationPredicateBucket filter, PrefetchPathElement2Collection additionalPrefetchElements, ISortExpression sorter, IDataAccessAdapter adapter )
{
PrefetchPath2 prefetch = new PrefetchPath2( (int)EntityType.RolesEntity );
prefetch.Add( RolesEntity.PrefetchPathUsersCollection );
if (additionalPrefetchElements != null)
{
foreach( IPrefetchPathElement2 element in additionalPrefetchElements )
{
prefetch.Add( element );
}
}
return FetchCollectionWithPrefetch( filter, sorter, prefetch, adapter );
}
In the code in the original post, I add a sort clause to the users collection (I think), then I create a prefetch element and add it to the collection. The collection is then enumerated in the protected method and added to the prefetch in the protected method.
When I debug the code, the collection does contain an element so I am assuming it is the one that I added in the calling method.
I havent really used this particular overload with the manager templates so I am not sure if I am doing things as expected.