Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

767 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 767 Results Showing 19151 - 19175 of 24441

ID Name Category Price Stock Rating Reviews SKU
19710 Bulk Product e96842f4 Books $843.10 274 1.6 64 BULK-537df9ff
19711 Bulk Product 56583a11 Sports & Outdoors $928.74 121 4.2 37 BULK-5fb3386d
19712 Bulk Product eea05517 Toys & Games $456.12 164 1.7 58 BULK-51209b1e
19713 Bulk Product 300521ed Toys & Games $761.07 199 3.1 0 BULK-4127161c
19714 Bulk Product 2f44d969 Toys & Games $460.38 126 2.9 33 BULK-fb3b2c85
19715 Bulk Product 4b5987fc Electronics $663.77 43 4.3 36 BULK-f2a7de50
19716 Bulk Product cfd96ec2 Clothing $177.40 225 3.9 68 BULK-f7cc0780
19717 Bulk Product 05c4a8fe Electronics $12.17 230 2.3 82 BULK-1e2a2392
19718 Bulk Product 054f04b6 Electronics $476.55 144 3.3 78 BULK-20bcf1d1
19719 Bulk Product 26a81e6a Toys & Games $661.86 415 3.0 25 BULK-b204ffed
19720 Bulk Product 037f8f3e Toys & Games $408.66 169 0.1 95 BULK-034898f9
19721 Bulk Product 76f29baa Toys & Games $468.41 493 1.1 90 BULK-427b7f8f
19722 Bulk Product 7c43c53e Books $280.05 293 1.5 91 BULK-362ceb93
19723 Bulk Product 6799503c Electronics $987.59 496 1.0 29 BULK-47eb4bec
19724 Bulk Product 26842601 Home & Garden $784.36 369 2.6 89 BULK-b32519e4
19725 Bulk Product 106a3fc1 Toys & Games $772.63 450 4.9 23 BULK-363e77db
19726 Bulk Product 41ea4adb Clothing $265.17 357 3.3 38 BULK-1e1e9c66
19727 Bulk Product a74e0d46 Toys & Games $444.33 104 1.4 68 BULK-5bcb80fa
19728 Bulk Product 0054ecd9 Clothing $190.05 494 0.1 73 BULK-59242fc4
19729 Bulk Product a76fb4d6 Home & Garden $387.82 75 4.9 40 BULK-deaf28dc
19730 Bulk Product 36c1a1b6 Sports & Outdoors $797.71 255 3.9 20 BULK-337caec5
19731 Bulk Product ffcf36a7 Books $628.96 332 2.7 3 BULK-3b560121
19732 Bulk Product 39a134f9 Sports & Outdoors $731.46 136 3.6 46 BULK-0d93ba4a
19733 Bulk Product 8ba335bd Books $315.44 407 4.8 86 BULK-33ff9f37
19734 Bulk Product 86dbe5c7 Electronics $136.17 184 2.6 76 BULK-f2795e96
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