Paul
I need to add the data to a tree view and order the data within the nodes to be based on Names not IDs.
The applySort only allow you to sort by one column. I need to sort by 4 different levels
Level1
Level2
Level3
Level4
FYI
I changed the query and got Order By Inconsistency
1.The following code returns order by data for each entity correctly only the first time.
Entity1 ordered by Descending
Entity2 ordered by Descending
Entity3 ordered by Descending
Entity4 ordered by Descending
query.AddOrderBy(Level1.Level1NameEntityColumn,ListSortDirection.Descending);
EntitySubquery subQueryLevel2 = query.AddSubquery(EntityRelations.Level1_Level2);
subQueryLevel2.AddOrderBy(Level2.LocationNameEntityColumn, ListSortDirection.Descending);
EntitySubquery subQueryLevel3 = subQueryLevel2.AddSubquery(EntityRelations.Level2_Level3);
subQueryLevel3.AddOrderBy(Level3.WorkSiteDescEntityColumn, ListSortDirection.Descending);
EntitySubquery subQueryLevel4 = subQueryLevel3.AddSubquery(EntityRelations.Level3_CostCentre);
subCostCentre.AddOrderBy(CostCentre.CostCentreDescriptionEntityColumn,ListSortDirection.Descending);
2. When I change the code (as follows) to make Entity1 Ascending. The returned data is correct
Entity1 ordered by Ascending
Entity2 ordered by Descending
Entity3 ordered by Descending
Entity4 ordered by Descending
query.AddOrderBy(Level1.Level1NameEntityColumn,ListSortDirection.Ascending);
EntitySubquery subQueryLevel2 = query.AddSubquery(EntityRelations.Level1_Level2);
subQueryLevel2.AddOrderBy(Level2.LocationNameEntityColumn, ListSortDirection.Descending);
EntitySubquery subQueryLevel3 = subQueryLevel2.AddSubquery(EntityRelations.Level2_Level3);
subQueryLevel3.AddOrderBy(Level3.WorkSiteDescEntityColumn, ListSortDirection.Descending);
EntitySubquery subQueryLevel4 = subQueryLevel3.AddSubquery(EntityRelations.Level3_CostCentre);
subCostCentre.AddOrderBy(CostCentre.CostCentreDescriptionEntityColumn,ListSortDirection.Descending);
3. When I change the code (as follows) to make Entity2 Ascending. The returned data is incorrect
Entity1 ordered by Ascending
Entity2 ordered by Descending
Entity3 ordered by Descending
Entity4 ordered by Descending
query.AddOrderBy(Level1.Level1NameEntityColumn,ListSortDirection.Ascending);
EntitySubquery subQueryLevel2 = query.AddSubquery(EntityRelations.Level1_Level2);
subQueryLevel2.AddOrderBy(Level2.LocationNameEntityColumn, ListSortDirection.Ascending);
EntitySubquery subQueryLevel3 = subQueryLevel2.AddSubquery(EntityRelations.Level2_Level3);
subQueryLevel3.AddOrderBy(Level3.WorkSiteDescEntityColumn, ListSortDirection.Descending);
EntitySubquery subQueryLevel4 = subQueryLevel3.AddSubquery(EntityRelations.Level3_CostCentre);
subCostCentre.AddOrderBy(CostCentre.CostCentreDescriptionEntityColumn,ListSortDirection.Descending);
By creating a new persistence manager each time the query is executed the code above works correctly.
Only the Entity1 “OrderBy” works correctly each time the sort direction is changed. (ie without creating a new persistence manager or removing entities)
By adding the "subquery.Top = 100" to all subquerys fixed the problem.
Using Top = 100 means using an arbitrary number for the number of records to return.
In SQL you use the "Top 100 percent" to return all associated records.
I know I can all retrieve Level1s apply a ApplySort() then interate through them all, get all Level2s attached to the first Level1, ApplySort to Level2s etc.....
Is this the way you recommend ?
Thanks