I have a PatientDocument which has a FK to a DocumentEntity.
I want to fetch a filtered collection of PatientDocuments, and in this result I want to order them by a property of the DocumentEntity.
I prefer a single query to be generated, but unfortunately I can't get it working.
While settling for less, I tried to fetch all the entities and do the sorting in-memory.
this is one of my attempts:
PatientDocumentCollection patientDocuments = new PatientDocumentCollection();
IPredicateExpression filter = new PredicateExpression(PatientDocumentFields.FolderID == 1);
RelationCollection relations = new RelationCollection();
relations.Add(PatientDocumentEntity.Relations.DocumentEntityUsingDocumentID);
IPrefetchPath prefetchPath = new PrefetchPath(EntityType.PatientDocumentEntity);
prefetchPath.Add(PatientDocumentEntity.PrefetchPathDocument, 1, null, relations);
patientDocuments.GetMulti(filter, prefetchPath);
ISortExpression sorter = new SortExpression(new SortClause(DocumentFields.IsDeleted, SortOperator.Descending));
IEntityView entityView = patientDocuments.CreateView(null, sorter);
I use the prefetchPath to get the FK property in the result, to enable sorting, but this doesn't work either... Any tips would be appreciated!