Group select and return exact quantity

2

Personal I'm using the entity and I have a query that returns some 2000 lines. After doing this:

base.Get(queryParameters)
.GroupBy(x => new { x.Id })

Until now it's normal, I work with pagedlist, where it is informed the number of the page that will be displayed and the quantity of items, eg:

-The return has 20 items, is informed page 2 and quantity 10, the return will be 10 items from the 11th to the 20th item in the list.

The problem is that I can only do it after having queried the 2000 rows in the bank and grouped them, which causes the delay to be very large, as there are some 'joins' in the middle.

Is there any way to group a query and paged it before the query is done in the database?

    
asked by anonymous 21.08.2018 / 04:50

2 answers

0

Mount your IQueryable<T> before calling the ToList() method that will be converted to a SQL query that will probably run faster than a pool within the memory.

    
21.08.2018 / 13:53
0

You would have to know the current page before doing ToList (), something like:

int numeroDeObjPorPagina = 10;

base.Get(queryParameters)
.GroupBy(x => new { x.Id })
.Skip(numeroDeObjPorPagina * paginaAtual)
.Take(numeroDeObjPorPagina)
.ToList();
    
21.08.2018 / 16:10