Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

38 ms

Page Size

50

Current Page

144 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 144 Results Showing 7151 - 7200 of 24441

ID Name Category Price Stock Rating Reviews SKU
7710 Bulk Product e2aa77fd Books $68.09 160 4.2 63 BULK-65d79f67
7711 Bulk Product b13d049d Home & Garden $732.83 32 2.3 99 BULK-7181b912
7712 Bulk Product a1fece7b Books $707.70 363 4.9 67 BULK-da4abc98
7713 Bulk Product da65eae5 Sports & Outdoors $377.09 450 2.4 60 BULK-67d1069c
7714 Bulk Product d8b6481f Electronics $143.76 425 5.0 29 BULK-ee460bbe
7715 Bulk Product da8b06bc Clothing $478.60 448 1.2 67 BULK-6c5e9dd1
7716 Bulk Product e4112db3 Books $212.56 342 4.2 56 BULK-ccff6a49
7717 Bulk Product c4c88064 Electronics $232.00 387 2.5 56 BULK-e0384725
7718 Bulk Product 0c4b46a3 Books $67.89 315 2.5 44 BULK-d11faade
7719 Bulk Product 5b902bd8 Sports & Outdoors $988.84 344 0.6 25 BULK-e98e5cf7
7720 Bulk Product 9aa4cbf0 Sports & Outdoors $243.77 154 1.6 29 BULK-b118b77a
7721 Bulk Product 119ff1de Sports & Outdoors $543.92 75 4.3 35 BULK-ea940cc4
7722 Bulk Product ae775bf6 Books $388.21 298 1.8 55 BULK-f994ee0c
7723 Bulk Product 3f1667c6 Electronics $674.74 175 4.7 21 BULK-189655eb
7724 Bulk Product 29846b3a Clothing $792.01 9 1.5 44 BULK-0ff15adf
7725 Bulk Product 3c3bfbbc Clothing $19.73 230 4.4 10 BULK-76a6b284
7726 Bulk Product b123b68f Home & Garden $443.04 177 0.1 77 BULK-72a7be00
7727 Bulk Product 3c0fc181 Books $342.87 59 3.7 47 BULK-4650d4c4
7728 Bulk Product 14cb084c Toys & Games $191.28 22 1.7 37 BULK-8356ea9e
7729 Bulk Product 98e9f77b Home & Garden $479.71 165 3.0 73 BULK-da1f89f9
7730 Bulk Product 26c8d2d2 Toys & Games $717.27 491 3.2 10 BULK-09e461ec
7731 Bulk Product 2a85d743 Books $716.99 395 2.0 14 BULK-77220ff9
7732 Bulk Product 598ef084 Toys & Games $691.19 120 2.5 99 BULK-a8c8ed80
7733 Bulk Product 48092bc2 Sports & Outdoors $412.03 419 2.6 18 BULK-40082e31
7734 Bulk Product dcd95174 Home & Garden $381.06 217 2.2 8 BULK-2626a4a3
7735 Bulk Product 273ecc1c Electronics $125.37 229 4.5 44 BULK-db8ee66c
7736 Bulk Product 5659d52f Home & Garden $475.26 126 1.8 40 BULK-c543bf0d
7737 Bulk Product b382f899 Books $740.35 475 4.1 49 BULK-cca447de
7738 Bulk Product f139c1a3 Home & Garden $372.91 274 0.2 86 BULK-46a8f5c4
7739 Bulk Product 0cbedcce Electronics $696.01 421 4.7 40 BULK-7fddcc96
7740 Bulk Product 2193c6f3 Home & Garden $609.07 346 3.5 84 BULK-9295474e
7741 Bulk Product c25afd9d Home & Garden $476.05 14 4.5 37 BULK-388b524c
7742 Bulk Product e909abe7 Clothing $955.20 228 1.9 97 BULK-592df791
7743 Bulk Product 141cbbd3 Clothing $238.15 413 2.5 84 BULK-04e2fffa
7744 Bulk Product cefaddd4 Clothing $157.98 396 3.5 59 BULK-e0cd5c1f
7745 Bulk Product d4bbe9a9 Clothing $552.82 289 4.2 96 BULK-3d51a596
7746 Bulk Product 9fe405c5 Toys & Games $504.80 355 3.7 94 BULK-52723c56
7747 Bulk Product 637ee628 Clothing $874.37 202 3.4 53 BULK-bc1bc161
7748 Bulk Product 91289789 Clothing $452.78 347 2.8 35 BULK-20eb1d8e
7749 Bulk Product ee7a7f13 Sports & Outdoors $73.77 460 0.4 63 BULK-e470a031
7750 Bulk Product 9b9e1c18 Electronics $640.30 160 3.1 30 BULK-b5e4bb75
7751 Bulk Product f32a1c00 Clothing $19.00 325 3.6 29 BULK-085d24f8
7752 Bulk Product 48c1f5f0 Sports & Outdoors $30.45 198 1.0 46 BULK-c59752db
7753 Bulk Product dccb6038 Sports & Outdoors $956.67 484 2.8 4 BULK-4e56e7c2
7754 Bulk Product 52a7454a Clothing $491.90 167 2.3 87 BULK-cea886b4
7755 Bulk Product ff953699 Electronics $516.30 39 3.3 79 BULK-f3fb96dc
7756 Bulk Product 812ec1b0 Sports & Outdoors $106.12 37 0.5 34 BULK-d558d35d
7757 Bulk Product f999fe94 Books $875.19 427 1.6 29 BULK-69a4c03a
7758 Bulk Product 4012ef4d Toys & Games $606.87 254 0.7 49 BULK-5b83c8de
7759 Bulk Product 4fdf4efe Electronics $853.04 109 1.6 73 BULK-df403c71
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