Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

972 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 972 Results Showing 24276 - 24300 of 24441

ID Name Category Price Stock Rating Reviews SKU
24835 Bulk Product b4840fe0 Clothing $85.23 27 2.6 89 BULK-1af6a041
24836 Bulk Product a043287a Books $628.57 208 0.6 72 BULK-fc1e40dd
24837 Bulk Product 362a5564 Sports & Outdoors $709.91 199 1.8 13 BULK-cdc503d9
24838 Bulk Product 12f2c990 Electronics $940.84 24 1.2 0 BULK-5d14a4a8
24839 Bulk Product e38bcc87 Books $335.80 372 4.6 60 BULK-480136ff
24840 Bulk Product f21c46a8 Sports & Outdoors $735.27 426 3.6 36 BULK-6e905b1f
24841 Bulk Product 0b2ee2d2 Sports & Outdoors $511.72 115 0.6 99 BULK-0640ea3b
24842 Bulk Product 7ab1789d Clothing $691.43 446 4.5 64 BULK-1febf8e9
24843 Bulk Product e5560fd0 Books $620.30 205 0.7 89 BULK-01ff9962
24844 Bulk Product fe2d0ab0 Home & Garden $411.41 268 3.9 40 BULK-66669173
24845 Bulk Product 5203fecb Sports & Outdoors $401.54 23 2.2 25 BULK-fd9ae4e0
24846 Bulk Product 39f9a561 Sports & Outdoors $339.87 321 4.0 87 BULK-f351fe80
24847 Bulk Product d9fae204 Sports & Outdoors $468.33 184 4.9 11 BULK-b8657350
24848 Bulk Product 74f48ff8 Books $868.89 252 3.0 51 BULK-07165de2
24849 Bulk Product f19794e5 Home & Garden $172.85 5 2.5 61 BULK-5fe2406f
24850 Bulk Product 532e4f53 Clothing $229.27 361 4.2 64 BULK-16eea98c
24851 Bulk Product 1f7f92f7 Books $847.71 336 2.2 89 BULK-a850dc9b
24852 Bulk Product 6c0a09cd Home & Garden $888.67 389 1.9 55 BULK-43ecd170
24853 Bulk Product eeeac47f Sports & Outdoors $94.43 439 2.5 50 BULK-f4a8f81a
24854 Bulk Product 7933be8c Sports & Outdoors $623.76 198 1.6 66 BULK-b90c418e
24855 Bulk Product c44f2c18 Home & Garden $591.46 263 3.9 16 BULK-12fd970f
24856 Bulk Product 354a99c1 Books $32.57 259 3.7 28 BULK-e4ce2c5d
24857 Bulk Product cd2a8bf1 Sports & Outdoors $721.29 485 2.8 3 BULK-f95a170d
24858 Bulk Product f07fbcac Books $569.07 437 1.0 31 BULK-ab4833df
24859 Bulk Product 5ab1ff1f Sports & Outdoors $409.49 43 2.5 94 BULK-11ba8611
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