Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

552 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 552 Results Showing 13776 - 13800 of 24441

ID Name Category Price Stock Rating Reviews SKU
14335 Bulk Product a3aac58f Sports & Outdoors $694.50 268 0.3 62 BULK-0a45b798
14336 Bulk Product 89330a05 Home & Garden $134.36 289 3.1 17 BULK-00c62525
14337 Bulk Product d3e75388 Clothing $633.73 332 3.4 13 BULK-47cecea6
14338 Bulk Product 3c73d183 Sports & Outdoors $81.19 170 3.2 1 BULK-d4ce8094
14339 Bulk Product b9a028c6 Toys & Games $593.31 75 0.8 97 BULK-cee64414
14340 Bulk Product de48421c Clothing $739.76 293 0.7 71 BULK-0ecc802c
14341 Bulk Product 23543e4c Clothing $264.20 181 4.2 16 BULK-e2980c45
14342 Bulk Product 5a9c651a Books $398.41 401 1.2 25 BULK-a16646be
14343 Bulk Product 2f282c0f Toys & Games $181.30 391 2.4 93 BULK-c0591823
14344 Bulk Product 095ecb83 Clothing $76.98 122 0.5 17 BULK-23cd4360
14345 Bulk Product ea0ed0af Clothing $543.38 40 3.0 61 BULK-02f9957d
14346 Bulk Product 8780906f Sports & Outdoors $78.35 374 3.9 38 BULK-5ebd5cdd
14347 Bulk Product a5bca5e9 Toys & Games $400.59 222 0.7 72 BULK-42437116
14348 Bulk Product 33a45da0 Books $127.61 98 1.5 49 BULK-05e6fc71
14349 Bulk Product 0f8b3eed Books $990.52 228 3.2 41 BULK-9f759cac
14350 Bulk Product a5617437 Toys & Games $22.19 175 1.7 37 BULK-aa809e5a
14351 Bulk Product 9b6dbc16 Books $608.86 230 2.7 35 BULK-6efc1690
14352 Bulk Product 61326b4c Home & Garden $487.34 444 3.2 17 BULK-0a1af15c
14353 Bulk Product 9048a59a Books $867.53 147 4.6 9 BULK-504134e5
14354 Bulk Product e61d68b9 Books $521.85 9 1.5 55 BULK-6e0ffb8e
14355 Bulk Product 6a3ee23e Home & Garden $227.62 402 4.0 97 BULK-1212e1d5
14356 Bulk Product 8dc30a4b Books $942.34 184 3.1 52 BULK-5b907dcc
14357 Bulk Product e25bc228 Electronics $467.13 192 2.9 97 BULK-215321ec
14358 Bulk Product 1aa5fec4 Clothing $336.56 11 3.0 3 BULK-a8a522de
14359 Bulk Product 8cdf2640 Books $601.71 2 2.5 64 BULK-5d9856f3
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