Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

35 ms

Page Size

25

Current Page

703 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 703 Results Showing 17551 - 17575 of 24441

ID Name Category Price Stock Rating Reviews SKU
18110 Bulk Product e5c031fc Home & Garden $972.30 466 0.7 79 BULK-815bc29d
18111 Bulk Product b285a284 Books $983.32 442 0.9 87 BULK-fa1aa8a5
18112 Bulk Product f745becd Electronics $835.97 368 4.0 56 BULK-49a6c78f
18113 Bulk Product c2ef9546 Home & Garden $146.62 341 2.6 51 BULK-6d9f804d
18114 Bulk Product bc562ab0 Electronics $936.73 158 4.2 73 BULK-4decc869
18115 Bulk Product 8c9306e1 Sports & Outdoors $30.43 421 4.7 41 BULK-94fc1103
18116 Bulk Product c7a8a7d2 Home & Garden $570.17 480 3.9 16 BULK-05f08997
18117 Bulk Product 8b0661fb Clothing $675.93 28 0.4 66 BULK-0021aa76
18118 Bulk Product 87f1471f Home & Garden $806.06 261 0.5 79 BULK-b6e38371
18119 Bulk Product afcda75e Clothing $361.73 448 1.4 49 BULK-9ed98e1a
18120 Bulk Product 24cee67b Books $196.89 79 3.6 36 BULK-aa7b8732
18121 Bulk Product f3607bf8 Books $363.58 13 0.6 47 BULK-4a6ec724
18122 Bulk Product 59ac3161 Home & Garden $531.97 298 4.4 98 BULK-aa4620a0
18123 Bulk Product cacf7584 Home & Garden $753.18 447 1.4 91 BULK-2d417787
18124 Bulk Product e81b8c2a Home & Garden $284.91 35 4.1 22 BULK-00b24ebc
18125 Bulk Product 49400556 Sports & Outdoors $131.01 429 2.4 87 BULK-2e5bf5f3
18126 Bulk Product becbf2b0 Toys & Games $987.78 459 1.3 52 BULK-90116307
18127 Bulk Product da1ae14a Books $666.98 474 1.7 7 BULK-52cdc6d2
18128 Bulk Product 000585c4 Electronics $832.73 177 1.1 84 BULK-07747760
18129 Bulk Product 87807259 Home & Garden $955.14 160 1.6 22 BULK-dde63cc2
18130 Bulk Product 98205a24 Home & Garden $634.88 333 3.1 78 BULK-038c4879
18131 Bulk Product 680d13f4 Clothing $528.22 459 0.9 4 BULK-7432d1be
18132 Bulk Product 5cab1414 Sports & Outdoors $718.13 409 3.4 8 BULK-2598fe63
18133 Bulk Product 6d548688 Clothing $961.66 12 3.1 58 BULK-a2080ad4
18134 Bulk Product d29baa8d Toys & Games $267.76 45 2.1 11 BULK-a00fb8cf
Implementation Code
// Efficient pagination with Skip and Take
public async Task<PaginatedResult<DemoProduct>> GetPaginatedProductsAsync(int page, int pageSize)
{
    // Get total count (cached if possible)
    var totalCount = await _context.DemoProducts.CountAsync(p => p.IsActive);
    
    // Get page of results
    var items = await _context.DemoProducts
        .Where(p => p.IsActive)
        .OrderBy(p => p.Id) // Important: Must have ORDER BY for consistent paging
        .Skip((page - 1) * pageSize) // OFFSET in SQL
        .Take(pageSize) // FETCH NEXT in SQL
        .AsNoTracking() // No tracking needed for read-only
        .ToListAsync();

    return new PaginatedResult<DemoProduct>
    {
        Items = items,
        TotalCount = totalCount,
        Page = page,
        PageSize = pageSize
    };
}
Pagination Best Practices
  • Always use OrderBy: Skip/Take require stable sorting for consistent results
  • Use AsNoTracking(): Pagination queries are typically read-only
  • Consider caching: Cache total count if dataset changes infrequently
  • Limit max page size: Prevent users from requesting too many records at once
  • Use indexed columns: Ensure ORDER BY columns are indexed for performance