Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

50

Current Page

418 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 418 Results Showing 20851 - 20900 of 24441

ID Name Category Price Stock Rating Reviews SKU
21410 Bulk Product e79d62eb Clothing $232.74 394 3.2 10 BULK-92ae360d
21411 Bulk Product fb2c6763 Electronics $509.02 154 3.4 48 BULK-5cbaa72c
21412 Bulk Product 280ec1df Home & Garden $368.63 87 0.8 0 BULK-e7955330
21413 Bulk Product aa0963a0 Toys & Games $177.46 368 2.3 96 BULK-294f240a
21414 Bulk Product 5db7c200 Books $368.77 488 4.2 91 BULK-2043097c
21415 Bulk Product 1a4209c6 Home & Garden $279.68 106 2.4 71 BULK-1c462ef3
21416 Bulk Product 4d8e7a43 Electronics $54.99 421 3.3 16 BULK-c91b47c4
21417 Bulk Product 4a162059 Books $771.92 186 1.5 5 BULK-0dfe37c6
21418 Bulk Product f4d99bc1 Clothing $669.06 339 3.3 26 BULK-210777b3
21419 Bulk Product b5ea3848 Sports & Outdoors $322.38 208 2.8 78 BULK-5b13eb64
21420 Bulk Product e6c54414 Home & Garden $656.32 5 2.1 6 BULK-479de62c
21421 Bulk Product c42c807a Books $1,007.57 301 1.8 7 BULK-c73dc021
21422 Bulk Product 8c9d8ebd Sports & Outdoors $991.82 199 4.8 77 BULK-5f7bd1ec
21423 Bulk Product 500a0f5c Books $427.09 438 3.3 63 BULK-fa282f61
21424 Bulk Product fa611140 Electronics $489.85 341 0.7 55 BULK-cf7510a8
21425 Bulk Product 2510ac54 Electronics $781.11 9 2.4 27 BULK-c6fe6785
21426 Bulk Product 779839e5 Toys & Games $258.15 42 1.8 69 BULK-3f59dfe5
21427 Bulk Product 108034ba Toys & Games $62.64 421 1.8 33 BULK-a7227550
21428 Bulk Product bdad9da8 Clothing $669.08 111 1.1 80 BULK-e2360579
21429 Bulk Product 7e9ab257 Toys & Games $191.40 152 0.3 17 BULK-02641421
21430 Bulk Product 4c913a34 Sports & Outdoors $340.46 479 3.4 59 BULK-0ea46d21
21431 Bulk Product 8c17da97 Sports & Outdoors $55.68 117 0.1 95 BULK-da0a7371
21432 Bulk Product 1a8fdb1a Books $521.27 106 1.8 66 BULK-81a1921f
21433 Bulk Product 0a09f4eb Home & Garden $529.65 454 3.8 14 BULK-f249cb33
21434 Bulk Product 137bca73 Books $918.82 368 4.2 21 BULK-f5cb6627
21435 Bulk Product 335ecbcf Toys & Games $261.15 53 0.6 87 BULK-eed53855
21436 Bulk Product a399f2cf Sports & Outdoors $665.08 150 3.4 37 BULK-77f3d546
21437 Bulk Product 6e12f6b1 Electronics $186.17 392 3.9 58 BULK-bd115e63
21438 Bulk Product 1c9c12e9 Home & Garden $653.96 21 4.7 69 BULK-031c977a
21439 Bulk Product c165b6dc Books $140.11 81 0.0 7 BULK-6c5ec1b7
21440 Bulk Product 03c9de00 Sports & Outdoors $554.98 315 0.0 60 BULK-e5a4fe37
21441 Bulk Product fa49f9c3 Clothing $263.95 395 3.0 78 BULK-4bff2318
21442 Bulk Product f8e3505e Books $194.28 301 2.8 12 BULK-c57c2096
21443 Bulk Product 4f3d59ed Sports & Outdoors $13.92 74 4.2 90 BULK-feae3e1e
21444 Bulk Product af2a6198 Sports & Outdoors $248.63 197 1.1 88 BULK-1017926a
21445 Bulk Product e47b2bab Books $756.77 400 1.4 63 BULK-b5ef45e6
21446 Bulk Product 221adb6e Clothing $668.73 17 3.4 41 BULK-dad3240e
21447 Bulk Product 89869b4e Clothing $435.82 122 1.7 11 BULK-17fb4e24
21448 Bulk Product 7a3b4242 Sports & Outdoors $424.48 301 3.5 48 BULK-6c6064a2
21449 Bulk Product 25f9cd33 Toys & Games $344.61 299 2.6 10 BULK-139807ae
21450 Bulk Product 8324bfa5 Home & Garden $289.27 458 4.2 82 BULK-f4492958
21451 Bulk Product 5e585c4c Sports & Outdoors $139.03 437 3.9 36 BULK-5380f61d
21452 Bulk Product 63f498ef Electronics $139.63 63 2.4 42 BULK-e5269597
21453 Bulk Product 4c284e66 Sports & Outdoors $848.17 367 1.9 43 BULK-92da236b
21454 Bulk Product b177fae3 Electronics $897.55 68 4.2 80 BULK-cdf443ed
21455 Bulk Product fec54dc3 Clothing $467.58 174 2.5 15 BULK-32ab67bd
21456 Bulk Product 4cc1c4a0 Home & Garden $662.73 304 2.8 39 BULK-2752ec15
21457 Bulk Product e721d35e Toys & Games $223.47 205 2.7 3 BULK-d34f181b
21458 Bulk Product e4435372 Electronics $423.36 253 0.3 78 BULK-56192047
21459 Bulk Product 9ef6912a Electronics $979.12 328 4.2 77 BULK-9076756d
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