There are a number of ways to do this, but specifically without resorting a classic selection, the most efficient way would be with a https://doc.4d.com/4Dv17/4D/17.2/entitySelectiontoCollection.305-4387628.en.htmltoCollection>. The first parameter permits you to include the properties to extract from the entity selection as a comma separated list.
$cPersonNames:=ds.Person.all().orderBy(“FirstName, LastName”).toCollection(“FirstName, Father.FirstName”)
COLLECTION TO ARRAY($cPersonNames;
There are further ways to improve the efficiency of your code. Sorting an entity selection is extremely slow compared with sorting a collection of the same. If the only two values you’re returning are FirstName and Father.FirstName I don’t really see what sense it makes to sort by FirstName then by LastName as in your example, since LastName isn’t included in the result. It would then be possible to orderBy(“FirstName”) on the collection rather than on the entity selection.