Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

813 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 813 Results Showing 20301 - 20325 of 24441

ID Name Category Price Stock Rating Reviews SKU
20860 Bulk Product 0f686c6e Books $162.33 43 0.7 64 BULK-4fa68861
20861 Bulk Product c696535d Home & Garden $788.21 98 4.8 64 BULK-51fa13cb
20862 Bulk Product 7f944449 Electronics $759.16 371 0.6 52 BULK-8923c16b
20863 Bulk Product c7875edb Clothing $106.62 47 0.3 93 BULK-2b3a80e7
20864 Bulk Product f461b67f Sports & Outdoors $286.85 375 2.7 62 BULK-2a399319
20865 Bulk Product b30502e9 Home & Garden $362.42 407 3.3 77 BULK-1501c7ad
20866 Bulk Product d636f86c Home & Garden $748.91 376 4.6 37 BULK-0b5e9f5b
20867 Bulk Product 21c94dc1 Clothing $110.92 147 0.7 54 BULK-aed01231
20868 Bulk Product 311a5c41 Toys & Games $942.85 335 0.8 0 BULK-732a18df
20869 Bulk Product 67d721b8 Clothing $407.12 338 0.3 95 BULK-0ce603e7
20870 Bulk Product 6d5caca1 Clothing $970.98 472 2.2 42 BULK-1aa332bb
20871 Bulk Product b4a03213 Clothing $993.12 124 1.8 34 BULK-4c23fa7f
20872 Bulk Product c8e7889f Books $919.16 234 1.7 19 BULK-5383b730
20873 Bulk Product eb313b08 Sports & Outdoors $567.99 22 4.0 5 BULK-7bc2c03d
20874 Bulk Product 21e75e3b Home & Garden $346.57 480 3.2 32 BULK-6a7a909c
20875 Bulk Product 590d8897 Electronics $756.69 333 0.2 10 BULK-7899e035
20876 Bulk Product 5c4b3277 Books $412.95 226 4.6 65 BULK-5d3eee06
20877 Bulk Product 9aa97665 Home & Garden $668.08 51 1.2 43 BULK-f697928f
20878 Bulk Product b8a05c8b Home & Garden $844.35 25 3.3 12 BULK-9cb3a724
20879 Bulk Product 5c2c815a Clothing $495.47 46 0.0 44 BULK-e160581a
20880 Bulk Product 28597e07 Sports & Outdoors $539.34 16 1.5 80 BULK-f5309374
20881 Bulk Product 5362ec97 Electronics $614.49 106 0.9 45 BULK-9f849fde
20882 Bulk Product cff2b403 Clothing $132.35 308 1.2 74 BULK-1457e25e
20883 Bulk Product 6dbb019a Books $621.77 356 1.9 16 BULK-b9711dbf
20884 Bulk Product adfadf29 Sports & Outdoors $946.63 214 2.7 85 BULK-d5bcc5b3
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