This is a migrated thread and some comments may be shown as answers.

Problem using aggregates with included fields

1 Answer 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bert
Top achievements
Rank 1
Veteran
Bert asked on 01 Apr 2021, 08:10 AM

Hi,

I have  problem when I use aggregates on included fields in EF Core. Let me try to explain:

I have following queriable data:

 IQueryable<TblCarrier> queriableData = context.TblCarriers
                        .Include(x => x.CarPosU)
                        .Include(x => x.CarPosToNavigation)
                        .Include(x => x.CarArtU)
                        .AsQueryable();

 

The code herunder is working fine:

<GridAggregates>    
                <GridAggregate Field="CarArtUid" Aggregate="@GridAggregateType.Count" />
            </GridAggregates>

            <GridColumns>
                <GridColumn Field="CarUid" FieldType="@(typeof(long))" Title="Uid" Width="150" Editable="false" Filterable="true">
                </GridColumn>

                <GridColumn Field="CarBarcode" FieldType="@(typeof(long))" Title="Barcode" Width="150" Editable="false" Filterable="true"/>
                <GridColumn Field="CarTsCreation" FieldType="@(typeof(DateTime))" Title="Ts Created" DisplayFormat="{0:dd/MM/yyyy HH:mm:ss.fff}" Width="200" Editable="false" Filterable="true"/>
                <GridColumn Field="CarTsLastMove" FieldType="@(typeof(DateTime))" Title="Ts Moved" DisplayFormat="{0:dd/MM/yyyy HH:mm:ss.fff}" Width="200" Editable="false" Filterable="true"/>      
                <GridColumn Field="CarDescription" FieldType="@(typeof(string))" Title="Description" Width="200" Editable="@(this.RoleLevel>=eRoles.Administrator)"  Filterable="true"/>
                <GridColumn Field="CarArtUid" FieldType="@(typeof(long))" Title="Article" Width="200" Editable="@(this.RoleLevel>=eRoles.Developer)" Filterable="true">
                       <GroupHeaderTemplate>
                            Count: (@context.Count)
                        </GroupHeaderTemplate> 
                    
                    </GridColumn>

But when I try this, The context.count value is null:

<GridAggregates>    
                <GridAggregate Field="CarArtU.ArtErpCode" Aggregate="@GridAggregateType.Count" />
            </GridAggregates>

            <GridColumns>
                <GridColumn Field="CarUid" FieldType="@(typeof(long))" Title="Uid" Width="150" Editable="false" Filterable="true">
                </GridColumn>

                <GridColumn Field="CarBarcode" FieldType="@(typeof(long))" Title="Barcode" Width="150" Editable="false" Filterable="true"/>
                <GridColumn Field="CarTsCreation" FieldType="@(typeof(DateTime))" Title="Ts Created" DisplayFormat="{0:dd/MM/yyyy HH:mm:ss.fff}" Width="200" Editable="false" Filterable="true"/>
                <GridColumn Field="CarTsLastMove" FieldType="@(typeof(DateTime))" Title="Ts Moved" DisplayFormat="{0:dd/MM/yyyy HH:mm:ss.fff}" Width="200" Editable="false" Filterable="true"/>      
                <GridColumn Field="CarDescription" FieldType="@(typeof(string))" Title="Description" Width="200" Editable="@(this.RoleLevel>=eRoles.Administrator)"  Filterable="true"/>
                <GridColumn Field="CarArtU.ArtErpCode" FieldType="@(typeof(long))" Title="Article" Width="200" Editable="@(this.RoleLevel>=eRoles.Developer)" Filterable="true">
                       <GroupHeaderTemplate>
                            Count: (@context.Count)
                        </GroupHeaderTemplate> 
                    
                    </GridColumn>

 

The griddata is refreshed with the onread event

 DataEnvelope<T> dataToReturn = null;
                if (_Request.Groups.Count > 0)
                {
                    // Group again => Do grouping on local data
                    if (Result.Data != null)
                    {
                        Result = await Result.Data.ToDataSourceResultAsync(_Request);

                        dataToReturn = new DataEnvelope<T>
                        {
                            GroupedData = Result.Data.Cast<AggregateFunctionsGroup>().ToList(),
                            TotalItemCount = Result.Total
                        };
                        _GridData = dataToReturn.GroupedData.Cast<object>().ToList();
                    }
                }
                else
                {
                    dataToReturn = new DataEnvelope<T>
                    {
                        CurrentPageData = Result.Data.Cast<T>().ToList(),
                        TotalItemCount = Result.Total
                    };
                    _GridData = dataToReturn.CurrentPageData.Cast<object>().ToList();

                }

The grouped data seems to be fine. (See attached screenshot). The aggregate items key is CarArtU-ArtErpCode. Shouldn't that be CarArtU.ArtErpCode?

Thanks

 

 

 

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 01 Apr 2021, 01:08 PM

Hello Bert,

Does setting only the field of the model like in our docs help (note how it is not prefixed by the name of the class):

<GridAggregate Field="ArtErpCode" Aggregate="@GridAggregateType.Count" />

compared to the original:

<GridAggregate Field="CarArtU.ArtErpCode" Aggregate="@GridAggregateType.Count" />

Regards,
Marin Bratanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Bert
Top achievements
Rank 1
Veteran
Answers by
Marin Bratanov
Telerik team
Share this question
or