protected virtual DbAggregate VisitAggregate(DbAggregate aggregate)
        {
            // Currently only function or group aggregate are possible
            DbFunctionAggregate functionAggregate = aggregate as DbFunctionAggregate;

            if (functionAggregate != null)
            {
                return(VisitFunctionAggregate(functionAggregate));
            }

            DbGroupAggregate groupAggregate = (DbGroupAggregate)aggregate;

            return(VisitGroupAggregate(groupAggregate));
        }
        protected virtual DbGroupAggregate VisitGroupAggregate(DbGroupAggregate aggregate)
        {
            DbGroupAggregate result = aggregate;

            if (aggregate != null)
            {
                IList <DbExpression> newArguments = this.VisitExpressionList(aggregate.Arguments);
                Debug.Assert(newArguments.Count == 1, "Group aggregate had more than one argument?");

                if (!object.ReferenceEquals(aggregate.Arguments, newArguments))
                {
                    result = CqtBuilder.GroupAggregate(newArguments[0]);
                }
            }
            return(result);
        }