I have an entity, ParentEntity, which has a collection of ChildEntity objects, exposed through property Children. When I access the children through the parent, I want them sorted in a particular order.
I used to use code like this:
dim p as new ParentEntity
dim sort as new SortExpression
'...
'create the appropriate sort expression
'...
p.Children.SortClauses=sort
p.FetchUsingPK(...)
Then p.Children would be sorted in the proper order.
Since I upgraded to the latest libraries and designer, this no longer works. When I do
p.Children.SortClauses=sort
the code attempts to fetch p.Children. Since p's primary key isn't set yet, it doesn't come back with anything, but the collection is still marked as fetched (_alreadyFetchedChildren=True).
Once I fetch p and then try to use p.Children, there's nothing in the collection, because the fetch isn't done again.
So what's the proper way to set the sort order for a relation, so the items are retrieved in the desired order? Am I supposed to do p.Children.GetMulti(...) after I've fetched p? It seems there needs to be a way to set the sort order before the initial fetch is attempted; otherwise there's always a redundant database read.