Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

50

Current Page

106 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 106 Results Showing 5251 - 5300 of 24441

ID Name Category Price Stock Rating Reviews SKU
5810 Bulk Product 852f14c4 Home & Garden $656.67 118 3.0 39 BULK-49085a3f
5811 Bulk Product ce66dd91 Sports & Outdoors $911.14 176 2.3 2 BULK-625cf392
5812 Bulk Product 09c40657 Toys & Games $685.25 255 3.2 86 BULK-522d7991
5813 Bulk Product 8160ab0b Electronics $659.01 140 3.6 13 BULK-bf3956d2
5814 Bulk Product 1c240633 Clothing $576.40 384 2.0 11 BULK-fdbe5ead
5815 Bulk Product 55561952 Clothing $518.00 57 0.1 99 BULK-995338dd
5816 Bulk Product 4b8eef9c Toys & Games $735.69 77 2.9 56 BULK-18b20ae2
5817 Bulk Product f827c005 Toys & Games $578.38 458 1.2 84 BULK-517dbdbd
5818 Bulk Product 16fc30bc Electronics $893.78 20 0.4 55 BULK-0321ce4e
5819 Bulk Product a21b65fc Toys & Games $138.64 62 0.1 83 BULK-9a4ce143
5820 Bulk Product 6b18b17b Clothing $66.88 496 0.6 64 BULK-675c1829
5821 Bulk Product 344a9fcb Electronics $531.00 98 4.4 66 BULK-4b58ad28
5822 Bulk Product 95b9221b Books $308.34 475 3.0 49 BULK-003ccdb1
5823 Bulk Product 0675baa4 Electronics $371.45 358 4.4 24 BULK-435b5a1c
5824 Bulk Product ee10c58e Books $910.89 264 3.5 74 BULK-14598631
5825 Bulk Product 119c0a1b Books $747.45 101 1.0 42 BULK-630f6252
5826 Bulk Product 0b35a5fb Home & Garden $587.66 199 3.3 34 BULK-0651b6e3
5827 Bulk Product dd155f69 Clothing $168.61 403 2.9 50 BULK-02c98ead
5828 Bulk Product aaf250ac Clothing $420.46 335 4.8 11 BULK-4d7e5fa6
5829 Bulk Product 915626f6 Clothing $952.06 3 1.5 87 BULK-701360f1
5830 Bulk Product b8a9f1bb Clothing $726.31 99 2.1 43 BULK-df7c67fb
5831 Bulk Product 61beb19d Home & Garden $709.60 17 0.6 74 BULK-f808fe46
5832 Bulk Product 22b5557d Electronics $146.56 197 4.2 34 BULK-5bd77287
5833 Bulk Product bae82e5b Electronics $917.92 386 3.1 16 BULK-d7c9b36d
5834 Bulk Product fcf94220 Home & Garden $260.81 445 0.4 33 BULK-9a23842e
5835 Bulk Product 984a2e45 Books $713.73 132 4.6 93 BULK-9b799644
5836 Bulk Product 7ff0072e Home & Garden $442.78 274 2.0 94 BULK-a92f624e
5837 Bulk Product b9616610 Home & Garden $516.41 98 2.4 72 BULK-12abe594
5838 Bulk Product 7f1e96ba Electronics $383.91 140 3.7 31 BULK-64db1079
5839 Bulk Product bc96e5d0 Home & Garden $921.28 289 4.8 10 BULK-6de2742b
5840 Bulk Product 761e8319 Books $127.42 372 0.8 81 BULK-5fd8ff6c
5841 Bulk Product ffbe5021 Electronics $405.89 462 2.0 99 BULK-a034ca10
5842 Bulk Product 5798926d Toys & Games $358.21 115 2.1 71 BULK-419559ca
5843 Bulk Product 6664b265 Home & Garden $411.26 100 2.6 14 BULK-5a7ac7eb
5844 Bulk Product 9d25fe44 Electronics $144.91 220 4.1 75 BULK-1f0a7c65
5845 Bulk Product a9c07484 Electronics $803.70 305 0.9 37 BULK-2f3b8c3c
5846 Bulk Product 4b0365f5 Sports & Outdoors $760.23 65 0.4 20 BULK-d69ed0d6
5847 Bulk Product a243c3e0 Sports & Outdoors $633.08 389 3.3 19 BULK-d4b98feb
5848 Bulk Product c3b617c6 Clothing $641.17 342 2.9 65 BULK-1eda441c
5849 Bulk Product b72f3717 Toys & Games $498.50 416 2.3 42 BULK-62e6d262
5850 Bulk Product f42d5ace Clothing $622.17 401 4.5 90 BULK-716be5f9
5851 Bulk Product 394bbd4e Electronics $477.55 433 3.2 7 BULK-06bc26fd
5852 Bulk Product 0a85780f Clothing $342.35 172 1.3 21 BULK-96588dc9
5853 Bulk Product f07a3e0a Electronics $241.05 323 0.3 7 BULK-39233b15
5854 Bulk Product 19fe10b6 Electronics $555.93 266 0.9 12 BULK-772fb2ad
5855 Bulk Product 99654c93 Clothing $502.49 314 1.4 80 BULK-bbeb8f04
5856 Bulk Product a06f12d0 Books $810.48 231 4.1 25 BULK-d281b448
5857 Bulk Product e91f65d6 Sports & Outdoors $601.71 436 3.8 29 BULK-55a3285f
5858 Bulk Product 353c4e1e Electronics $414.38 466 0.1 92 BULK-ee702427
5859 Bulk Product 75e1c25e Electronics $974.41 106 0.4 97 BULK-5320c0a1
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