My application has a HouseholdEntity which holds Name ("Smith, John & Jane"), Address, Phone, etc. I have a ClientEntity which has a 1:1 relationship with HouseholdEntity. I also have an EmergencyContactEntity which has a 1:1 relationship with HouseholdEntity. The ClientEntity has a 1:n relationship with EmergencyContactEntity.
What I'm trying to get is a list of all the emergency contacts for a client, sorted by name (ClientEntity.EmergencyContact.Household.Name). The code that I'm using is:
emergencyContactListSorter = new SortExpression(HouseholdFields.Name | SortOperator.Ascending);
IPrefetchPathElement2 emergencyContactElement = ClientEntity.PrefetchPathEmergencyContact;
emergencyContactElement.SubPath.Add(EmergencyContactEntity.PrefetchPathHousehold, 0, null, null, emergencyContactListSorter);
prefetchPath.Add(emergencyContactElement);
However, the list is not sorted as expected. Can you tell me what I'm doing wrong?
If I use this code, the emergency contacts list is sorted as expected:
emergencyContactListSorter = new SortExpression(HouseholdFields.Name | SortOperator.Ascending);
IPrefetchPathElement2 emergencyContactElement = ClientEntity.PrefetchPathHouseholdCollectionViaEmergencyContact;
prefetchPath.Add(emergencyContactElement);
But I would rather use the syntax "ClientEntity.EmergencyContact[i].Household" rather than "ClientEntity.HouseholdCollectionViaEmergencyContact[i]".
Thanks for any help,
Jay