Skip to content

ToDataSourceResult() is not able to perform query when the DataSourceRequest object contains groupingΒ #8177

@kendo-bot

Description

@kendo-bot

As a result of an EF Core issue, the ToDataSourceResult() is not able to perform the query when the DataSourceRequest object contains grouping.

The problem occurs using the query below, assembled by Telerik routine:

var temp = _db.Pessoa
    .OrderBy(item => item.Email)
    .Skip(0)
    .Take(40)
    .GroupBy(item => item.Email)
    .OrderBy(g => g.Key)
    .Select(g => new AggregateFunctionsGroup
    {
        Key = g.Key,
        ItemCount = g.Count(),
        HasSubgroups = false,
        Member = "Email",
        AggregateFunctionsProjection = new
        {
            Count_Referencia = _db.Pessoa
                    .Select(t => new
                    {
                        t.IdPessoa,
                        t.Referencia,
                        t.Nome_RazaoSocial,
                        t.Apelido_Fantasia,
                        t.CPF_CNPJ,
                        t.RG_IE,
                        t.Email
                    })
                    .OrderBy(item => item.Email)
                    .Where(item => item.Email == g.Key)
                    .Count()
        },
        Items = g
    })
    .ToList();

In the routine where the AggregateFunctionsGroup is created, the Items property must not only be the query itself, but also the fields specified in the main Select. Or, the call to the Select() method must simply be added:

var temp = _db.Pessoa
    .OrderBy(item => item.Email)
    .Skip(0)
    .Take(40)
    .GroupBy(item => item.Email)
    .OrderBy(g => g.Key)
    .Select(g => new AggregateFunctionsGroup
    {
        Key = g.Key,
        ItemCount = g.Count(),
        HasSubgroups = false,
        Member = "Email",
        AggregateFunctionsProjection = new
        {
            Count_Referencia = _db.Pessoa
                    .Select(t => new
                    {
                        t.IdPessoa,
                        ...
                    })
                    .OrderBy(item => item.Email)
                    .Where(item => item.Email == g.Key)
                    .Count()
        },
        Items = g.Select(t => new
        {
            t.IdPessoa,
            ...
        })
    })
    .ToList();

This way, the issue does not occur.
For more information, refer to the forum thread.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions