Thanks for the reply. Here is a copy of my code which you can see is nearly identical:
DataAccessAdapter adapter = new DataAccessAdapter(true);
DataTable tags;
IRelationPredicateBucket bucket;
ResultsetFields fields;
ISortExpression sorter;
IGroupByCollection groupBy;
fields = new ResultsetFields(3);
fields.DefineField(KeywordFields.Keyword, 0, "Keyword", "Keyword");
fields.DefineField(KeywordFields.KeywordId, 1, "KeywordId", "Keyword");
fields.DefineField(ListingKeywordFields.KeywordId, 2, "Count", "ListingKeyword",
AggregateFunction.Count);
bucket = new RelationPredicateBucket();
bucket.Relations.Add(ListingKeywordEntity.Relations.KeywordEntityUsingKeywordId,
"ListingKeyword",
"Keyword", JoinHint.None);
groupBy = new GroupByCollection();
groupBy.Add(fields[0]);
groupBy.Add(fields[1]);
sorter = new SortExpression();
//sorter.Add(KeywordFields.Keyword | SortOperator.Descending);
tags = new DataTable();
adapter.FetchTypedList(fields, tags, bucket, 0, sorter, true, groupBy);
adapter.CloseConnection();
The sorter line here (currently commented out) does not work:
** //sorter.Add(KeywordFields.Keyword | SortOperator.Descending);**
There is one "slight" difference from my code and the example in the documentation. For the third field defined
fields.DefineField(ListingKeywordFields.KeywordId, 2, "Count", "ListingKeyword", AggregateFunction.Count);
They use the same Entity (EmployeeFields) for all of them, while I use two different entities. Could this be the problem??
Compare this
fields.DefineField(KeywordFields.Keyword, 0, "Keyword", "Keyword");
fields.DefineField(KeywordFields.KeywordId, 1, "KeywordId", "Keyword");
fields.DefineField(ListingKeywordFields.KeywordId, 2, "Count", "ListingKeyword", AggregateFunction.Count);
versus
fields.DefineField(EmployeeFields.FirstName, 0, "FirstNameManager", "Manager");
fields.DefineField(EmployeeFields.LastName, 1, "LastNameManager", "Manager");
fields.DefineField(EmployeeFields.LastName, 2, "NumberOfEmployees", "Employee", AggregateFunction.Count
);