private bool AssignAggregateFunction(Function function, QueryCriteria queryCriteria) { AggregateFunctionType agrFunctionType; switch (function.FunctionName) { case "max": agrFunctionType = AggregateFunctionType.MAX; break; case "min": agrFunctionType = AggregateFunctionType.MIN; break; case "avg": agrFunctionType = AggregateFunctionType.AVG; break; case "sum": agrFunctionType = AggregateFunctionType.SUM; break; case "count": agrFunctionType = AggregateFunctionType.COUNT; break; case "first": agrFunctionType = AggregateFunctionType.FIRST; break; case "last": agrFunctionType = AggregateFunctionType.LAST; break; default: agrFunctionType = AggregateFunctionType.NOTAPPLICABLE; break; } if (!agrFunctionType.Equals(AggregateFunctionType.NOTAPPLICABLE)) { if (function.Arguments.Count > 1) { throw new QuerySystemException(ErrorCodes.Query.INVALID_NUMBER_OF_AGGREGATE_FUNCTION_ARGUMENTS, new[] { function.ToString() }); } if (function.ArgumentFunctions.Count > 0) { foreach (var func in function.ArgumentFunctions) { var functionName = func.FunctionName; if (functionName.Equals("max") || functionName.Equals("min") || functionName.Equals("avg") || functionName.Equals("sum") || functionName.Equals("count") || functionName.Equals("first") || functionName.Equals("last")) { //An aggregate function shouldn't contain any aggregate function in its arguments. throw new QuerySystemException(ErrorCodes.Query.INVALID_AGGREGATE_FUNCTION_ARGUMENTS, new[] { functionName }); } } } function.ExecutionType = FunctionExecutionType.Aggregate; queryCriteria.AddAggregateFunction(agrFunctionType, function.Arguments[0]); return(true); } return(false); }