Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

488 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 488 Results Showing 12176 - 12200 of 24441

ID Name Category Price Stock Rating Reviews SKU
12735 Bulk Product 048d7a9b Clothing $588.59 97 3.3 34 BULK-b6e46574
12736 Bulk Product 4e5f3642 Toys & Games $382.10 109 0.9 9 BULK-c71990f0
12737 Bulk Product b7e70761 Sports & Outdoors $255.76 413 3.7 90 BULK-2057d681
12738 Bulk Product f31e6707 Electronics $239.55 22 3.4 68 BULK-b6417f82
12739 Bulk Product bf0c6de4 Home & Garden $76.23 422 3.5 39 BULK-2b7183b2
12740 Bulk Product 8ee96939 Electronics $19.11 108 0.8 17 BULK-a323049c
12741 Bulk Product 1de0956f Toys & Games $486.77 111 1.0 32 BULK-4872ba5d
12742 Bulk Product f786bf07 Books $368.92 233 1.6 64 BULK-a6065cf7
12743 Bulk Product fa947222 Clothing $801.78 325 2.4 72 BULK-c256e9ea
12744 Bulk Product 29d0cfeb Electronics $444.52 308 2.6 45 BULK-af0e29ba
12745 Bulk Product b29224d6 Home & Garden $839.05 225 4.6 80 BULK-cc68ec85
12746 Bulk Product f748444b Books $825.93 75 2.0 77 BULK-bc453af2
12747 Bulk Product 423f41e0 Books $263.70 183 3.5 32 BULK-be149ba4
12748 Bulk Product 8fc0df76 Electronics $250.39 430 2.7 24 BULK-d29ad17c
12749 Bulk Product 27b4648d Toys & Games $552.83 207 0.8 92 BULK-38c4a17a
12750 Bulk Product 18a8ea43 Clothing $272.29 202 1.0 55 BULK-d86d8547
12751 Bulk Product 863296d8 Electronics $854.73 171 3.9 60 BULK-021a857c
12752 Bulk Product d11be6d9 Sports & Outdoors $74.96 450 3.7 28 BULK-789460b9
12753 Bulk Product b506788f Sports & Outdoors $201.80 153 3.6 93 BULK-f8b78186
12754 Bulk Product d20df01d Electronics $79.03 37 3.0 98 BULK-b1c30bf6
12755 Bulk Product ce314980 Electronics $174.08 177 1.1 95 BULK-74612c0a
12756 Bulk Product 582d8ce3 Home & Garden $837.94 52 2.1 1 BULK-386036c2
12757 Bulk Product 182d6967 Books $66.28 234 0.9 0 BULK-86122906
12758 Bulk Product 21fbe6fc Sports & Outdoors $252.13 374 2.1 61 BULK-36428a9a
12759 Bulk Product 2b94ad31 Books $763.07 385 0.1 33 BULK-00a9095c
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