/// <summary> /// Builds the aggregate expression. /// </summary> /// <param name="aggregateExpression">The aggregate expression.</param> /// <param name="context">The context.</param> /// <returns>AggregateExpression.</returns> private static AggregateExpression BuildAggregateExpression(Model.AggregateExpression aggregateExpression, FromEntityContext context) { string[] aggregateExpressionParts = aggregateExpression.AggregateMethod.Alias.Split(':'); string method = aggregateExpressionParts.Length == 2 ? aggregateExpressionParts[1].Substring(3) : aggregateExpressionParts[0].Substring(3); // string method = aggregateExpression.AggregateMethod.Alias.Substring(3); AggregateMethod aggregateMethod = (AggregateMethod)Enum.Parse(typeof(AggregateMethod), method, true); AggregateExpression expression = new AggregateExpression { AggregateMethod = aggregateMethod, Expression = aggregateExpression.AggregatedExpression != null?BuildExpression(aggregateExpression.AggregatedExpression, context) : null }; // Validate expression if (expression.AggregateMethod != AggregateMethod.Count && expression.Expression == null) { EventLog.Application.WriteWarning(context.DebugInfo + "the aggregate id: {0} has invalid grouped expression.", aggregateExpression.Id.ToString()); return(null); // TODO: Log a warning } Guid key = Guid.NewGuid(); context.ReportExpressionMap[key] = aggregateExpression.SourceNode.Id; expression.ExpressionId = key; expression.EntityId = aggregateExpression.Id; return(expression); }
protected override ScalarExpression OnBuildQuery(QueryBuilderContext context) { var aggregateNode = context.GetNode(this); var result = new EDC.ReadiNow.Metadata.Query.Structured.AggregateExpression { NodeId = aggregateNode.NodeId, AggregateMethod = Method }; if (Method != AggregateMethod.Count) { result.Expression = Argument.BuildQuery(context); } return(result); }