Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

50

Current Page

342 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 342 Results Showing 17051 - 17100 of 24441

ID Name Category Price Stock Rating Reviews SKU
17610 Bulk Product 418abe04 Books $487.45 436 2.3 84 BULK-0d7515ca
17611 Bulk Product dbc36e8c Clothing $131.23 304 4.1 6 BULK-db971d33
17612 Bulk Product 27c7e7b5 Sports & Outdoors $848.66 476 3.9 32 BULK-3bcb6125
17613 Bulk Product 7659bda5 Clothing $391.43 95 2.6 63 BULK-842bd302
17614 Bulk Product 53619bdc Home & Garden $732.12 406 0.3 35 BULK-8b23fcd5
17615 Bulk Product 3b372bf7 Sports & Outdoors $366.71 407 2.1 87 BULK-35936858
17616 Bulk Product 8d21d080 Electronics $299.81 101 0.0 24 BULK-4856d202
17617 Bulk Product fa9866c2 Books $155.43 116 2.9 11 BULK-fb27eade
17618 Bulk Product 37aaa1b0 Clothing $559.35 150 1.0 40 BULK-88cf4c1e
17619 Bulk Product 6f87f036 Sports & Outdoors $600.96 415 3.6 1 BULK-6fb7c8f1
17620 Bulk Product 4dc2e5da Toys & Games $231.16 149 3.1 96 BULK-897d3fb1
17621 Bulk Product 4b7d9ade Books $290.36 284 2.8 16 BULK-7f76d1b0
17622 Bulk Product 92dddc79 Electronics $973.44 392 0.4 10 BULK-99c06736
17623 Bulk Product 41d40c32 Clothing $262.71 485 4.8 31 BULK-e7abc149
17624 Bulk Product 378717bc Sports & Outdoors $967.49 111 3.7 49 BULK-47025d93
17625 Bulk Product 2d16a568 Sports & Outdoors $27.92 134 4.1 18 BULK-6aa0ee69
17626 Bulk Product 8204df2e Home & Garden $881.84 413 0.0 49 BULK-1d49e673
17627 Bulk Product 7fa4d05e Home & Garden $816.29 122 1.4 59 BULK-12e1baa9
17628 Bulk Product 4d0df00a Sports & Outdoors $705.61 72 2.4 3 BULK-0f7bb441
17629 Bulk Product 3ad404fb Electronics $101.41 253 0.3 66 BULK-02f19185
17630 Bulk Product bcc848ba Home & Garden $334.31 380 4.3 91 BULK-16710c19
17631 Bulk Product 24be5d0f Sports & Outdoors $762.79 9 0.5 94 BULK-dd4715a6
17632 Bulk Product 743fd289 Clothing $415.84 145 2.5 58 BULK-94701453
17633 Bulk Product 3a604952 Clothing $219.18 407 0.8 33 BULK-6e1cd487
17634 Bulk Product 2a3a7103 Clothing $240.78 179 4.4 50 BULK-c1597a09
17635 Bulk Product d26c1783 Toys & Games $775.58 141 3.9 48 BULK-b2ec933e
17636 Bulk Product 4671006f Clothing $803.45 327 1.0 31 BULK-cbde6e5a
17637 Bulk Product 23fcd9a2 Sports & Outdoors $119.82 51 4.5 23 BULK-56727b2d
17638 Bulk Product fd9b9db4 Clothing $568.45 386 4.9 19 BULK-d3f00d69
17639 Bulk Product 3805600d Home & Garden $559.59 49 0.1 64 BULK-1da5103a
17640 Bulk Product 2060348a Home & Garden $978.43 50 2.1 36 BULK-11ef1df2
17641 Bulk Product 4ee545ca Sports & Outdoors $804.14 464 2.5 47 BULK-7fd27dfc
17642 Bulk Product c13b859c Sports & Outdoors $528.17 335 0.8 67 BULK-e26ea500
17643 Bulk Product fe09c100 Sports & Outdoors $84.35 447 0.4 72 BULK-5290540b
17644 Bulk Product d33ffc1b Sports & Outdoors $137.75 179 0.2 65 BULK-dcbe4b2a
17645 Bulk Product afd062db Electronics $361.45 306 0.4 45 BULK-b03f1d7a
17646 Bulk Product 0a04072d Home & Garden $460.58 290 2.8 37 BULK-4047f89b
17647 Bulk Product eeb194ce Toys & Games $297.85 92 1.2 81 BULK-82881318
17648 Bulk Product 113d4731 Toys & Games $341.22 33 0.8 10 BULK-afd4a8ad
17649 Bulk Product eff0f7d7 Home & Garden $681.09 356 3.4 42 BULK-ef947ea0
17650 Bulk Product 32188ab3 Electronics $183.92 32 3.8 92 BULK-c11fe299
17651 Bulk Product a98999c8 Toys & Games $979.37 381 4.9 13 BULK-020ee4d9
17652 Bulk Product 2807364e Home & Garden $311.53 66 4.6 29 BULK-c2b447b9
17653 Bulk Product 1a4514d6 Clothing $77.24 340 2.0 49 BULK-79761f85
17654 Bulk Product e9fc308d Clothing $110.18 347 0.6 90 BULK-e186f04a
17655 Bulk Product 6a2f4dd6 Toys & Games $331.75 480 1.1 23 BULK-e00971c0
17656 Bulk Product a15c95a5 Sports & Outdoors $540.24 149 3.0 79 BULK-7404d411
17657 Bulk Product 251979e4 Toys & Games $974.62 457 4.7 77 BULK-760bd35d
17658 Bulk Product 3764a8dc Clothing $853.16 40 0.9 10 BULK-6188f6d2
17659 Bulk Product efec2f2f Clothing $616.47 310 1.0 35 BULK-ed9d6842
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