Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

689 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 689 Results Showing 17201 - 17225 of 24441

ID Name Category Price Stock Rating Reviews SKU
17760 Bulk Product ccf0ae42 Clothing $493.71 336 3.6 99 BULK-5b4b5ff3
17761 Bulk Product c66d107f Home & Garden $564.53 496 1.4 14 BULK-a8453e0c
17762 Bulk Product 80c5d1e1 Clothing $257.69 179 3.9 32 BULK-756a6fed
17763 Bulk Product a41c97d7 Sports & Outdoors $922.17 404 4.6 2 BULK-52898786
17764 Bulk Product 0f42e754 Books $106.46 191 0.7 88 BULK-30ccab35
17765 Bulk Product f16ce905 Home & Garden $595.98 129 1.9 20 BULK-4f0fa079
17766 Bulk Product c73c6294 Clothing $902.35 335 4.7 52 BULK-8eb66689
17767 Bulk Product 6dcd7da3 Electronics $528.16 195 5.0 60 BULK-95f2c129
17768 Bulk Product b6fcdda8 Home & Garden $643.12 405 3.6 71 BULK-3a4c9aa7
17769 Bulk Product 59d3f69a Sports & Outdoors $728.38 255 1.8 75 BULK-b2d9e6c4
17770 Bulk Product 50d0a9d6 Clothing $607.82 489 3.0 8 BULK-0dc3b377
17771 Bulk Product 8f784bbc Toys & Games $176.67 41 3.1 96 BULK-c955866e
17772 Bulk Product 71f87727 Sports & Outdoors $305.63 64 4.0 83 BULK-b0a1127c
17773 Bulk Product 354df756 Books $478.95 289 2.8 14 BULK-9cf49a25
17774 Bulk Product 1aae78cf Toys & Games $992.60 326 1.2 92 BULK-bff6352b
17775 Bulk Product 2515ea4d Toys & Games $699.09 67 1.2 31 BULK-47a3c4c4
17776 Bulk Product 6981bea6 Clothing $650.63 305 3.6 4 BULK-971bfd50
17777 Bulk Product dfcba9cc Electronics $456.43 105 4.7 45 BULK-f57a7654
17778 Bulk Product d4ac8281 Electronics $542.15 137 4.1 62 BULK-7c95e9c9
17779 Bulk Product c5980939 Toys & Games $881.94 63 3.8 19 BULK-a65ba1c1
17780 Bulk Product ffaf48d8 Toys & Games $464.98 212 0.7 38 BULK-0aa4d81c
17781 Bulk Product 2774016a Sports & Outdoors $553.11 204 1.5 2 BULK-6cff77d4
17782 Bulk Product d14b1223 Home & Garden $680.39 443 0.1 2 BULK-a1105475
17783 Bulk Product e7027421 Toys & Games $158.79 112 4.5 17 BULK-0de0e65d
17784 Bulk Product 9b593ed4 Electronics $573.81 353 0.3 73 BULK-bb9eec6a
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