Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

50

Current Page

421 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 421 Results Showing 21001 - 21050 of 24441

ID Name Category Price Stock Rating Reviews SKU
21560 Bulk Product 036e78ee Clothing $895.55 209 3.6 39 BULK-9e817e08
21561 Bulk Product 07ec6e50 Clothing $583.12 167 1.9 29 BULK-dd481d03
21562 Bulk Product b6a45918 Sports & Outdoors $312.80 303 3.3 96 BULK-8c4937a3
21563 Bulk Product c50f47c4 Electronics $914.64 332 5.0 55 BULK-9b581c7f
21564 Bulk Product ccff8dca Home & Garden $604.31 227 2.9 32 BULK-d7ee7663
21565 Bulk Product 30a50517 Clothing $280.12 37 3.3 15 BULK-64b10d80
21566 Bulk Product 09367dda Home & Garden $815.92 480 2.4 18 BULK-2eb0088a
21567 Bulk Product 7aed117a Toys & Games $550.53 359 3.8 4 BULK-462d5428
21568 Bulk Product d80cbeb0 Clothing $290.46 263 1.4 16 BULK-b6ecd3b9
21569 Bulk Product 77ae67cf Clothing $819.35 228 1.0 89 BULK-83d8d56e
21570 Bulk Product 5b0b5dea Home & Garden $796.20 77 0.7 89 BULK-e1e4ea9b
21571 Bulk Product dc63d80f Electronics $13.98 403 3.7 32 BULK-b25b5150
21572 Bulk Product 5f3f5261 Sports & Outdoors $946.24 409 0.4 66 BULK-ce308a16
21573 Bulk Product d784779f Sports & Outdoors $792.37 235 2.2 25 BULK-50d5de7e
21574 Bulk Product c2de3be9 Clothing $46.56 371 2.6 89 BULK-98cacf10
21575 Bulk Product 752660ce Sports & Outdoors $157.98 418 1.4 95 BULK-e847dfb8
21576 Bulk Product 8b94731c Toys & Games $62.26 201 4.1 27 BULK-f344b776
21577 Bulk Product 7507e28a Home & Garden $268.81 129 1.2 77 BULK-32702c72
21578 Bulk Product 5c754dd0 Clothing $921.51 49 3.9 96 BULK-13ad0e19
21579 Bulk Product 4cb252d6 Sports & Outdoors $246.59 22 2.1 12 BULK-984dadc3
21580 Bulk Product f9ebd759 Home & Garden $929.61 443 1.3 69 BULK-be028ad2
21581 Bulk Product 5ef78954 Home & Garden $750.97 332 0.1 77 BULK-6d659ebd
21582 Bulk Product cb5bf2b6 Toys & Games $409.75 336 0.5 59 BULK-a2739931
21583 Bulk Product a2ab6f4a Home & Garden $585.67 252 4.4 46 BULK-361955dd
21584 Bulk Product 4200089d Sports & Outdoors $723.93 51 2.9 27 BULK-88b4f0ad
21585 Bulk Product e8295dd9 Books $490.06 380 4.1 54 BULK-fb6b7159
21586 Bulk Product 7285dd06 Electronics $844.01 232 4.4 32 BULK-ceaa6431
21587 Bulk Product 76d4aa18 Books $633.09 246 3.3 98 BULK-545da763
21588 Bulk Product 64a0c70b Home & Garden $25.87 74 1.2 54 BULK-d80d09be
21589 Bulk Product 95d9e2a9 Electronics $969.30 82 0.3 64 BULK-67ba6182
21590 Bulk Product 602b8b1a Toys & Games $917.31 9 1.1 89 BULK-ffe0de52
21591 Bulk Product b306b129 Books $735.64 341 4.8 53 BULK-9e1656a9
21592 Bulk Product e3cfc5e9 Books $622.01 263 4.7 87 BULK-744e816a
21593 Bulk Product f764e42f Books $335.94 111 2.2 74 BULK-7ebd0959
21594 Bulk Product 1f293514 Electronics $948.33 378 0.2 8 BULK-4bbc1dd7
21595 Bulk Product 76c957b3 Books $404.74 42 2.2 4 BULK-b30eda57
21596 Bulk Product 67474e38 Toys & Games $620.19 330 2.3 25 BULK-7a297618
21597 Bulk Product 2cc467d4 Clothing $594.51 149 1.3 5 BULK-014e3228
21598 Bulk Product 0790aeab Toys & Games $109.25 130 4.3 34 BULK-44253c84
21599 Bulk Product 5c1f638b Clothing $244.74 113 1.1 28 BULK-25231ace
21600 Bulk Product 43e7756f Clothing $420.66 185 2.1 65 BULK-24ee9f67
21601 Bulk Product 0ebbb6e1 Home & Garden $634.87 240 3.1 53 BULK-c35fb818
21602 Bulk Product e911a791 Sports & Outdoors $185.18 301 1.0 63 BULK-e1a015c3
21603 Bulk Product 7da9cb67 Electronics $649.78 84 2.1 86 BULK-66e92d54
21604 Bulk Product 1ebd89bc Clothing $565.15 368 4.5 20 BULK-908d2a4f
21605 Bulk Product 3e058ccf Sports & Outdoors $357.92 22 0.8 87 BULK-171369a3
21606 Bulk Product e65d9266 Books $22.71 447 3.3 72 BULK-f46be294
21607 Bulk Product eb402c3a Clothing $868.95 185 2.5 65 BULK-e45bfaf7
21608 Bulk Product 80c261f8 Electronics $586.11 497 1.3 78 BULK-e0528fcd
21609 Bulk Product efaf9dae Clothing $792.45 51 4.2 89 BULK-e839d1d8
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