Group select and return exact amount

Asked

Viewed 45 times

2

Guys I’m using Entity and I have a query that returns some 2000 lines. After doing this:

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

Until then it is normal,I work with pagedlist, where is informed the page number that will be displayed and the amount of items of it, example:

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

The problem is that I can only do it after having consulted the 2000 lines in the bank and grouped them, which makes the delay very large, because 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?

  • https://stackoverflow.com/questions/19766300/pagedlist-with-entity-framework-getting-all-records

2 answers

0

You would have to know the current page before making the Tolist(), something like :

int numeroDeObjPorPagina = 10;

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

0

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.