TypedList - Aggregate function

Posts   
 
    
rracer99
User
Posts: 58
Joined: 11-Mar-2007
# Posted on: 12-May-2007 11:39:39   

Hello,

Must an aggregate policy be set for each column retrieved or is there a simpler solution for this model:

invoices invoice_line_item clients

the typed list involves something like this:

invoice.number invoice.date clients.name invoice_line_item.total_amount (this is defined as SUM aggregate in the llblgen designer)

There will be of course many more fields spanning many more tables, however only the line_item totals require the sum aggregate.

So in this situation, I will get a runtime error :

Column XYZ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Must an aggregate policy be applied for each field in this typed list?

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 12-May-2007 16:06:24   

yes, you must supply a group by clause. in essensance your building this sql statement:

Select field_a, field_b, sum(field_c) from mytable group by field_a, field_b

here some generice code that may help

public IGroupByCollection GetGroupBy(IEntityFieldsCore fields)
{
     IGroupByCollection toReturn = new GroupByCollection();
     foreach(IEntityFieldCore field in fields)
     {
             If(field.AggregateExpression == AggregateType.None || field.ExpressionToApply == null)
             {
                  toReturn.Add(field);
             }
     }

     if ( toReturn.Count == 0)
     {
          toReturn = null;
     }

     return toReturn;
}