Returning a Sum that has a filter

Posts   
 
    
tmpcl
User
Posts: 20
Joined: 21-Sep-2006
# Posted on: 10-Jan-2007 20:41:40   

I am trying to return the total number of regular hours a particular employee works during a date range.

I believe that I have the filter coded correctly but I'm having trouble trying to apply the aggregate. I looked at the documentation and figured that the GetScalar was the way to go but I'm not sure what to include in the 3rd parameter.

Can anyone help me see the light?


IPredicateExpression filter = new PredicateExpression(TimeOffHistoryFields.EmployeeId == employeeID);
filter.Add(TimeOffHistoryFields.TimeOffTypeId == RegularTime.TimeOffTypeId);
filter.Add(new FieldBetweenPredicate(TimeOffHistoryFields.Date, startDate, endDate);        
                
TimeOffHistoryCollection totalHours = new TimeOffHistoryCollection();
                            
hours = (int)totalHours.GetScalar(TimeOffHistoryFieldIndex.TimeOffTypeId, (TimeOffHistoryFields.Hours*1), AggregateFunction.Sum, filter);

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 11-Jan-2007 06:42:03   

Have you tried this:

hours = (int)adapter.GetScalar(TimeOffHistoryFields.Hours, null, AggregateFunction.Sum, filter);

Quoted from the reference manual:

C#
public object GetScalar( IEntityField2 field, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter )

field Field to which to apply the aggregate function and expression **expressionToExecute ** The expression to execute. Can be null **aggregateToApply ** Aggregate function to apply. **filter ** The filter to apply to retrieve the scalar Return Value the scalar value requested