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

ToDataSourceResult applied to IQueryable with included navigation properties

1 Answer 743 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mauro
Top achievements
Rank 1
Mauro asked on 28 Apr 2020, 08:36 AM

Hello, I'm currently devloping a .NETCore application. The application is divided into three layers: Data Layer(with models definition), Service Layer (to retrieve data and return it as IQueryable objects) and the Application Layer (where Telerik is installed).

My controller read action in the ApplicationLayer is as follows:

 public IActionResult ReadAziende([FromServices] IAziendaService service, [DataSourceRequest] DataSourceRequest request)
        {
              var aziende = service.ListWithIncludes().ToDataSourceResult(request, m => _mapper.Map<IndiceAziendaVM>(m));
            return Json(aziende);
        }

 

The Service Layer action ListWithIncludes is as follows:

  public IQueryable<AziendaFullIncludeDTO> ListWithIncludes()
        {
            return _context.Aziende
                .Include(a => a.Settore)
                .Include(a => a.Indirizzi)
                .Include(a => a.Tags)
                    .ThenInclude(a => a.Tag)
                .Include(a => a.CodiceAteco)
                .Include(a => a.TenantDataAccess)
                    .ThenInclude(a => a.Tenant)
                .AsNoTracking()               
                .Select(a => _mapper.Map<AziendaFullIncludeDTO>(a))   ;
        }

 

The Service Layer is correctly returning the DTO with included fields in an IQueryable Object but as soon as I pass it to ToDataSourceResult all included fields get lost.
What is the correct way to apply ToDataSourceResult  to an IQueryable Object with Included navigation properties?
Thanks.

 

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 01 May 2020, 04:30 AM

Hello,

The issue is most probably observed because ToDataSourceResult extension method applies sorting automatically based on the parameters passed by the Grid. I assume this overwrites your sort expression. For more information you can refer to this forum thread where a similar scenario have been discussed.

Regards,
Plamen
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Mauro
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or