Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

774 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 774 Results Showing 19326 - 19350 of 24441

ID Name Category Price Stock Rating Reviews SKU
19885 Bulk Product c1844824 Toys & Games $24.49 63 2.4 80 BULK-9da79ba6
19886 Bulk Product 7f1f4756 Sports & Outdoors $551.71 313 2.6 35 BULK-5dbfcd72
19887 Bulk Product 2e46e00f Books $218.22 498 4.4 72 BULK-ee8d1358
19888 Bulk Product a7624b6a Toys & Games $843.16 382 0.2 50 BULK-28052bdb
19889 Bulk Product 91170f55 Clothing $747.80 339 2.6 90 BULK-42a74970
19890 Bulk Product 6be5a774 Electronics $622.52 456 0.5 54 BULK-7c5eccb2
19891 Bulk Product 21d103e7 Books $922.51 320 0.5 50 BULK-6872ed74
19892 Bulk Product cb7067f9 Home & Garden $882.12 244 0.0 34 BULK-43e911a0
19893 Bulk Product 8ba79e99 Electronics $32.72 233 2.0 17 BULK-371c9562
19894 Bulk Product c8069233 Clothing $971.33 442 1.7 23 BULK-260c9827
19895 Bulk Product 8e36d2cd Sports & Outdoors $765.26 379 4.1 38 BULK-8834a1d4
19896 Bulk Product 320400a3 Home & Garden $593.26 66 2.8 42 BULK-02b78e26
19897 Bulk Product b70dd52b Books $237.90 173 3.6 55 BULK-b936aed4
19898 Bulk Product 30cdbf8a Home & Garden $706.29 108 4.7 30 BULK-9f6c7290
19899 Bulk Product 22c7e54b Home & Garden $898.72 309 4.8 45 BULK-3f99d222
19900 Bulk Product 1e5fc0c8 Books $969.19 488 3.9 8 BULK-7d6ab177
19901 Bulk Product 418e50a8 Home & Garden $652.67 113 2.8 4 BULK-75b938f2
19902 Bulk Product 78aa2458 Clothing $511.26 171 0.2 27 BULK-57d4deb8
19903 Bulk Product f80fcf46 Home & Garden $18.72 363 1.5 79 BULK-02c3e357
19904 Bulk Product a10a44b8 Electronics $292.61 217 2.8 53 BULK-8d83ff93
19905 Bulk Product 972e6f86 Toys & Games $746.95 453 0.8 1 BULK-5e56ebf2
19906 Bulk Product 441ccec5 Sports & Outdoors $717.37 177 0.8 95 BULK-5446821a
19907 Bulk Product a144dd40 Home & Garden $547.34 359 3.9 76 BULK-dc43856a
19908 Bulk Product 1578cbad Clothing $560.15 397 0.4 22 BULK-b5c991fe
19909 Bulk Product 0cd4f446 Home & Garden $595.36 68 0.6 90 BULK-5bc19392
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