Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

57 ms

Page Size

25

Current Page

319 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 319 Results Showing 7951 - 7975 of 24441

ID Name Category Price Stock Rating Reviews SKU
8510 Bulk Product 80f3e104 Home & Garden $100.30 98 2.4 12 BULK-fc4fbce0
8511 Bulk Product 59123493 Toys & Games $304.93 127 5.0 4 BULK-b7be4cf2
8512 Bulk Product 0f816c1f Clothing $387.63 205 0.6 86 BULK-a0c57c4a
8513 Bulk Product ca1ef35b Home & Garden $344.87 495 1.9 47 BULK-a18e01e8
8514 Bulk Product 9b8d0750 Toys & Games $71.64 453 1.8 93 BULK-0949d77f
8515 Bulk Product 863d86ca Books $229.24 275 0.1 33 BULK-1cb518b2
8516 Bulk Product f08e2d83 Home & Garden $346.84 295 2.2 52 BULK-0dc5d935
8517 Bulk Product ff940a82 Books $513.80 322 2.1 37 BULK-b264abbe
8518 Bulk Product 0c16e3cb Sports & Outdoors $781.07 200 0.6 51 BULK-e6b9453e
8519 Bulk Product 0c033cf9 Home & Garden $705.32 311 2.1 21 BULK-c313489c
8520 Bulk Product f076344d Electronics $431.05 254 4.1 86 BULK-ca0059af
8521 Bulk Product 8e71aa29 Sports & Outdoors $710.88 221 1.0 6 BULK-4d6d2389
8522 Bulk Product f8a30d22 Sports & Outdoors $458.56 469 1.1 14 BULK-2c574307
8523 Bulk Product 8b8ddb77 Sports & Outdoors $64.81 246 4.0 63 BULK-008c2678
8524 Bulk Product e999198b Toys & Games $885.37 447 1.1 99 BULK-0140ccf2
8525 Bulk Product 6a027193 Books $476.30 272 4.3 32 BULK-37c1e467
8526 Bulk Product 69f9ba27 Clothing $264.24 157 1.8 59 BULK-6a5fec77
8527 Bulk Product d9ae86e2 Clothing $760.90 404 2.0 4 BULK-68c7da94
8528 Bulk Product c15b924d Books $888.70 373 4.1 18 BULK-bd21d735
8529 Bulk Product 03a52714 Toys & Games $50.11 346 4.5 85 BULK-64aebd92
8530 Bulk Product 1cf25281 Electronics $257.59 139 2.9 43 BULK-2fbdd829
8531 Bulk Product 99c7147c Sports & Outdoors $264.86 95 2.8 57 BULK-1546070d
8532 Bulk Product 918fb3cb Books $33.82 190 1.1 32 BULK-c69e6fc4
8533 Bulk Product 9e55164e Toys & Games $28.14 388 4.6 4 BULK-5713afb0
8534 Bulk Product e13515d6 Electronics $392.31 142 0.9 18 BULK-54c3e442
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