protected override Task MergeAsync(MergeContext context) { if (aggregation != null) { return(aggregation(context)); } return(Task.CompletedTask); }
protected override async Task ExecuteContextAsync(MethodContext context) { var groupResolver = (context as IContext).Scope.Resolve <IGroupResolver>(); if (groupResolver == null) { throw new NotSupportedException($"Aggregate function {MethodInfo.MethodName} requires a group resolver in context"); } if (groupResolver.Size == 0) { context.SetResult(SqlObject.NullOf(MethodInfo.ReturnType)); return; } SqlExpression input = null; if (context.ArgumentCount > 0) { input = context.Argument(0); } using (var seed = new InitializeContext(context, input)) { await InitializeAsync(seed); if (seed.Result != null) { input = seed.Result; } if (!seed.Iterate) { context.SetResult(input); return; } } SqlObject output = null; if (input != null) { if (input is SqlReferenceExpression) { var reference = (SqlReferenceExpression)input; output = await IterateReference(context, reference.ReferenceName, groupResolver); } else { output = await IterateValues(context, input, groupResolver); } } using (var aggregate = new MergeContext(context, output)) { await MergeAsync(aggregate); if (aggregate.Output != null) { output = aggregate.Output; } } context.SetResult(output); }
protected virtual Task MergeAsync(MergeContext context) { return(Task.CompletedTask); }