Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

33 ms

Page Size

25

Current Page

459 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 459 Results Showing 11451 - 11475 of 24441

ID Name Category Price Stock Rating Reviews SKU
12010 Bulk Product e5bf035a Home & Garden $93.74 295 2.7 29 BULK-39e14373
12011 Bulk Product b71e51b7 Books $630.94 362 2.1 95 BULK-f8a4945d
12012 Bulk Product d9f30ce2 Toys & Games $108.69 269 4.7 94 BULK-a4f90c0f
12013 Bulk Product 53e5a1cb Sports & Outdoors $262.19 108 3.8 61 BULK-0dc5d3d8
12014 Bulk Product 991b6895 Clothing $203.65 84 0.3 77 BULK-ba625599
12015 Bulk Product d1f8c8a7 Electronics $644.82 29 2.9 89 BULK-b6b3ba36
12016 Bulk Product 21c2e459 Toys & Games $453.98 489 0.8 91 BULK-debccab0
12017 Bulk Product d3e60bc5 Electronics $135.70 338 1.4 75 BULK-a8acedda
12018 Bulk Product 754d8e7b Sports & Outdoors $275.62 432 3.7 3 BULK-d92fc3ee
12019 Bulk Product 532fccb3 Sports & Outdoors $469.90 355 2.6 4 BULK-6e090ab9
12020 Bulk Product dde65052 Electronics $862.46 483 0.8 95 BULK-5fb629e2
12021 Bulk Product a4e6890e Home & Garden $998.58 409 4.9 32 BULK-8342f434
12022 Bulk Product fecc2c44 Sports & Outdoors $988.98 293 0.8 50 BULK-91001263
12023 Bulk Product 157488f8 Clothing $614.71 67 3.5 79 BULK-83ace3a0
12024 Bulk Product 454cbd39 Electronics $992.06 177 2.4 11 BULK-b1197d02
12025 Bulk Product fbe20157 Clothing $134.56 305 3.4 89 BULK-171ed4d7
12026 Bulk Product 47b4b7d0 Sports & Outdoors $448.44 46 4.6 55 BULK-2dcbbe5c
12027 Bulk Product 3b3be6c7 Electronics $133.56 255 2.8 79 BULK-501931ca
12028 Bulk Product 17bf134b Home & Garden $488.49 253 3.7 96 BULK-77fe176e
12029 Bulk Product 86657c1e Toys & Games $530.46 42 3.4 50 BULK-321c4c15
12030 Bulk Product 9374ab3c Clothing $301.99 195 2.1 37 BULK-6f179735
12031 Bulk Product bb448a03 Toys & Games $874.05 88 3.3 71 BULK-ce1d33e8
12032 Bulk Product 0d29ee54 Home & Garden $157.06 1 4.5 6 BULK-c007f64c
12033 Bulk Product a9ce5e30 Electronics $42.78 205 3.8 40 BULK-854002be
12034 Bulk Product 37a8a9f6 Electronics $958.29 463 1.5 45 BULK-7cf69fdd
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