Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

370 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 370 Results Showing 9226 - 9250 of 24441

ID Name Category Price Stock Rating Reviews SKU
9785 Bulk Product f6090ee1 Home & Garden $287.33 185 1.3 78 BULK-b0a13c5d
9786 Bulk Product a1f1f4b5 Electronics $922.84 199 3.5 8 BULK-050acfbe
9787 Bulk Product 75124496 Toys & Games $753.79 178 0.6 16 BULK-f988ea2b
9788 Bulk Product 820844e7 Sports & Outdoors $989.01 436 0.0 84 BULK-617866ca
9789 Bulk Product dc4330d4 Books $441.27 290 0.8 37 BULK-e05842a0
9790 Bulk Product d3acf228 Toys & Games $796.17 327 2.7 43 BULK-b350af3d
9791 Bulk Product ce558c11 Toys & Games $509.46 343 4.9 25 BULK-faafe764
9792 Bulk Product 722c42fd Sports & Outdoors $1,006.60 302 4.4 83 BULK-00b95c63
9793 Bulk Product 3a4de7ae Toys & Games $802.85 429 2.5 70 BULK-83fcdb12
9794 Bulk Product 5f6e985e Sports & Outdoors $919.77 408 3.4 28 BULK-2578fb16
9795 Bulk Product 96397ee0 Books $905.74 43 1.1 74 BULK-291f8067
9796 Bulk Product 22bd44b3 Sports & Outdoors $26.08 62 0.7 27 BULK-62fa1f6a
9797 Bulk Product 8be2af79 Toys & Games $787.51 6 3.0 65 BULK-5d908f7b
9798 Bulk Product 32b38f12 Clothing $136.17 142 0.7 67 BULK-ce2cee8a
9799 Bulk Product 7916ae4f Clothing $756.42 265 0.5 50 BULK-933ecd9a
9800 Bulk Product 633a2031 Home & Garden $233.54 346 1.7 3 BULK-8b7fa9c5
9801 Bulk Product 12c8af5d Electronics $553.87 441 2.3 67 BULK-1017f568
9802 Bulk Product cbeef629 Electronics $503.81 240 0.4 42 BULK-19a20433
9803 Bulk Product 2ecede9c Books $326.39 114 2.2 84 BULK-725417a7
9804 Bulk Product e81aafb1 Home & Garden $427.35 279 0.3 31 BULK-8286284a
9805 Bulk Product 10d45009 Sports & Outdoors $802.12 308 4.1 21 BULK-b08a6238
9806 Bulk Product cc2f7ef0 Books $630.84 224 0.3 32 BULK-e9bad3c5
9807 Bulk Product aba14e35 Books $111.61 404 2.9 56 BULK-c58e6311
9808 Bulk Product f11d276f Home & Garden $660.70 9 1.4 58 BULK-1022e07f
9809 Bulk Product 4df996e1 Home & Garden $846.96 307 2.9 22 BULK-fc64db05
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