I am trying to show some grid-aggregates in a grid column footer without any groups. But I'm seeing that the grid is geting ALL the records in the database to compute the Agregates. I am using the OnRead event and a DbSet with the ToDataSourceResult() extension method.
This is unnacceptable as I have 50k rows in the DB! As you can imagine the aggregates take forever to compute in-memory, but in the DB it woul be a super quick.
Also, I am building a generic grid for all my pages, so I need it to be easy to abstract, FYI
Any alternatives or workarounds? Could we not build a ExpressionTree for the aggregates and use IQueriable?
Thanks in advance!
...
<GridColumns>
<GridColumn Field="@nameof(PedidosDeClientes.Unidades)" Title="Unidades" Width="150px">
<FooterTemplate>
Sum: @context.Sum;
</FooterTemplate>
</GridColumn>
<GridColumn Field="@nameof(PedidosDeClientes.PesoBruto)" Title="PesoBruto" Width="150px">
<FooterTemplate>
Sum: @context.Sum;
</FooterTemplate>
</GridColumn>
</GridColumns>
<GridAggregates>
<GridAggregate Field=@nameof(PedidosDeClientes.Unidades) Aggregate="@GridAggregateType.Sum" />
<GridAggregate Field=@nameof(PedidosDeClientes.PesoBruto) Aggregate="@GridAggregateType.Sum" />
</GridAggregates>
...
public async Task OnRead( GridReadEventArgs args )
{
var r = await dbContext.PedidosDeClientes.ToDataSourceResultAsync( args.Request );
args.Data = r.Data;
args.Total = r.Total;
args.AggregateResults = r.AggregateResults;
}