Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

239 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 239 Results Showing 5951 - 5975 of 24441

ID Name Category Price Stock Rating Reviews SKU
6510 Bulk Product ca56e1c7 Toys & Games $695.11 172 4.1 91 BULK-aabf647c
6511 Bulk Product fc12c782 Books $123.40 99 2.7 48 BULK-89a298a5
6512 Bulk Product 6d2f11d3 Books $418.82 420 4.3 73 BULK-26e33492
6513 Bulk Product e3bd886a Sports & Outdoors $651.47 467 1.9 22 BULK-5fa9ed63
6514 Bulk Product 19829414 Toys & Games $120.15 345 2.7 55 BULK-e274e731
6515 Bulk Product f7152c4d Home & Garden $227.57 489 4.1 50 BULK-7739af7e
6516 Bulk Product f3488097 Clothing $663.17 254 2.5 65 BULK-44969b8a
6517 Bulk Product 10fafd6c Sports & Outdoors $708.79 114 1.1 15 BULK-4275873d
6518 Bulk Product eb03004f Electronics $364.31 34 1.2 2 BULK-66410dcc
6519 Bulk Product e70be0d7 Books $152.13 344 2.8 24 BULK-82265089
6520 Bulk Product 1034c9e3 Clothing $129.33 385 2.3 3 BULK-8ec22957
6521 Bulk Product c65e8162 Home & Garden $599.85 327 0.4 5 BULK-466806fc
6522 Bulk Product 92ccbfbc Books $556.95 480 0.1 54 BULK-123d4721
6523 Bulk Product 6a682ade Home & Garden $50.23 404 2.3 72 BULK-046884a1
6524 Bulk Product 2f8c0409 Clothing $331.77 483 2.6 39 BULK-3748475a
6525 Bulk Product 965a2148 Toys & Games $54.80 416 4.9 16 BULK-611ef096
6526 Bulk Product fd65b872 Clothing $518.43 315 2.2 29 BULK-03348f9f
6527 Bulk Product 8262d8eb Sports & Outdoors $53.09 434 1.1 0 BULK-97625215
6528 Bulk Product 55849aa9 Home & Garden $857.16 495 3.4 4 BULK-583e29b2
6529 Bulk Product 5f473aab Home & Garden $955.25 348 1.0 20 BULK-914ad905
6530 Bulk Product f4287149 Books $462.50 184 1.5 25 BULK-4fa2a67e
6531 Bulk Product 88dcacd9 Sports & Outdoors $620.30 397 2.3 28 BULK-b0cb6cbb
6532 Bulk Product 1dfb3d03 Clothing $468.29 110 3.7 6 BULK-8bc6ef2d
6533 Bulk Product dd109f4b Sports & Outdoors $765.59 225 0.6 43 BULK-915be706
6534 Bulk Product cc841002 Electronics $287.57 73 3.9 98 BULK-4c589a5a
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