Based on your samples in the documentation, you build your fields and group by clauses as such:
ResultsetFields fields = new ResultsetFields(3);
fields.DefineField(EmployeeFieldIndex.FirstName, 0, "FirstNameManager", "Manager");
fields.DefineField(EmployeeFieldIndex.LastName, 1, "LastNameManager", "Manager");
fields.DefineField(EmployeeFieldIndex.LastName, 2, "AmountEmployees", "Employee", AggregateFunction.Count);
// .... extra code omitted
IGroupByCollection groupByClause = new GroupByCollection();
groupByClause.Add(fields[0]);
groupByClause.Add(fields[1]);
To make my code a bit easier to read, I have build my code field and group by code as such:
// create the group by clause & result set fields
ResultsetFields fields = CustomResultsetFields.AuthorContentList();
IGroupByCollection groupByClause = new GroupByCollection();
for (int i = 0; i < fields.Count ; i++)
{
IEntityField2 field = fields[i] as IEntityField2;
if (field.AggregateFunctionToApply == AggregateFunction.None)
{
groupByClause.Add(field);
}
}
Based on my knowledge of SQL Server, you must include any fields not being aggregated in the group by clause.
So the question is this: Will using the field.AggregateFunctionToApply == AggregateFunction.None statement in the if block above always guarantee that all non-aggregated fileds in a dynamic typed list are included in the group by clause? I think it does. Also, do I need to account for expression fields at all?
Ultimately I would like to move the "for i" clause into a seperate function so I can write code like this:
IGroupByClause groupBy = MyGroupByClause(fields);