A
A
andy3010862015-06-24 00:28:21
ASP.NET
andy301086, 2015-06-24 00:28:21

How to optimize IPaginatedList?

Hi all. Faced such a problem. Used on EF 6 + IPaginationList project. The implementation has a field that receives the number of records Count(). The request hangs on this line of code.

public IPaginatedList<T> Apply<T>(IEnumerable<T> source)
        {
            var totalRecords = source.Count();
        .....

There are 250 thousand records in the database. Can it be optimized somehow? Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sumor, 2015-06-24
@andy301086

You have an IEnumerable method as input, which causes C# to enumerate the data source (SELECT * FROM source).
To instead generate a request for a quantity, you need to receive an IQueryable as an input. Then a query like SELECT count(*) FROM source will be generated.

T
Tsiren Naimanov, 2015-06-24
@ImmortalCAT

maybe make a query at the database level

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question