Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

406 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 406 Results Showing 10126 - 10150 of 24441

ID Name Category Price Stock Rating Reviews SKU
10685 Bulk Product 28ed9958 Clothing $126.84 396 1.0 75 BULK-f6dc2c5c
10686 Bulk Product a2333f7d Sports & Outdoors $409.75 371 2.8 24 BULK-5991d1d3
10687 Bulk Product 227c02ae Home & Garden $579.83 284 4.7 6 BULK-7108eff2
10688 Bulk Product c0c2659a Home & Garden $31.76 363 1.1 28 BULK-5d1af5d3
10689 Bulk Product b527e534 Books $386.72 89 0.8 77 BULK-6d3561d7
10690 Bulk Product 43542f3e Books $827.00 45 1.2 73 BULK-680e3d82
10691 Bulk Product 384ca041 Electronics $440.13 384 2.7 27 BULK-252e9892
10692 Bulk Product ec4890c4 Books $610.19 229 4.1 31 BULK-b6e6e1ac
10693 Bulk Product c2c2ecce Clothing $885.48 63 4.7 70 BULK-5ec3024d
10694 Bulk Product 03571621 Clothing $273.22 45 2.9 73 BULK-f5fe2512
10695 Bulk Product 3f8aca69 Clothing $527.00 348 0.5 37 BULK-fe350585
10696 Bulk Product dccffa93 Electronics $970.80 356 2.2 13 BULK-293e3a98
10697 Bulk Product 108843eb Books $520.78 425 4.7 25 BULK-ea8e3793
10698 Bulk Product ec0934db Toys & Games $795.45 214 2.9 37 BULK-fe06b53b
10699 Bulk Product df9cb5a7 Books $455.64 5 1.9 48 BULK-6a9166ac
10700 Bulk Product fcf58629 Home & Garden $603.21 416 0.2 72 BULK-a66c8b9a
10701 Bulk Product 4b813be1 Electronics $742.60 276 1.3 1 BULK-33d78525
10702 Bulk Product 4d71fa0e Toys & Games $763.86 16 4.2 3 BULK-cf025d75
10703 Bulk Product c5796626 Clothing $713.52 78 2.5 18 BULK-6c3c5a3c
10704 Bulk Product 0b9c45bf Books $905.32 134 0.6 1 BULK-795fcc32
10705 Bulk Product 00f1b327 Home & Garden $413.37 292 2.5 8 BULK-bdeec77e
10706 Bulk Product 7fb2d205 Clothing $884.62 481 4.0 79 BULK-d9cc84c7
10707 Bulk Product 4b90e822 Electronics $21.13 203 0.9 60 BULK-dda467ef
10708 Bulk Product e1b32a50 Home & Garden $590.34 40 2.2 30 BULK-a383fe03
10709 Bulk Product c96d665e Home & Garden $782.02 84 3.4 1 BULK-eecc5719
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