Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

28 ms

Page Size

25

Current Page

484 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 484 Results Showing 12076 - 12100 of 24441

ID Name Category Price Stock Rating Reviews SKU
12635 Bulk Product a7640b1f Sports & Outdoors $644.75 487 3.1 37 BULK-8c30734e
12636 Bulk Product d4982544 Sports & Outdoors $642.79 77 0.1 49 BULK-bb208c19
12637 Bulk Product 126eea77 Electronics $360.35 386 2.0 70 BULK-4bd3a6b2
12638 Bulk Product 95c32399 Sports & Outdoors $157.01 391 1.9 75 BULK-cbdb7faa
12639 Bulk Product 62056933 Toys & Games $388.14 139 4.5 44 BULK-0ad30e85
12640 Bulk Product 2d42b9c7 Clothing $959.06 102 4.6 80 BULK-44a75090
12641 Bulk Product 1aa35761 Toys & Games $647.27 417 3.8 32 BULK-1e94b91c
12642 Bulk Product e5237191 Electronics $614.21 213 2.1 39 BULK-27757d35
12643 Bulk Product 44e0dc3e Electronics $732.08 424 2.3 76 BULK-9e352693
12644 Bulk Product 2c6ea14d Clothing $488.82 463 1.5 36 BULK-4d74ce6c
12645 Bulk Product e1f2c565 Sports & Outdoors $346.51 8 4.4 25 BULK-f3e32eb9
12646 Bulk Product 5139b706 Home & Garden $123.85 363 0.5 7 BULK-a6a9c745
12647 Bulk Product b2a470fb Electronics $381.84 284 1.3 69 BULK-24d708b4
12648 Bulk Product 7837a1e4 Home & Garden $752.49 37 2.1 60 BULK-4b74aac1
12649 Bulk Product 027fae70 Toys & Games $83.54 284 2.5 74 BULK-2717796f
12650 Bulk Product ceef51eb Toys & Games $846.28 97 3.3 40 BULK-5b0f893d
12651 Bulk Product 6c435b30 Home & Garden $697.16 125 1.2 73 BULK-2eca06d3
12652 Bulk Product 6291f59a Sports & Outdoors $55.82 315 4.3 36 BULK-d81a3371
12653 Bulk Product 971c55cf Sports & Outdoors $316.44 33 2.7 51 BULK-f9ae0ecf
12654 Bulk Product cf9e166a Toys & Games $738.99 274 3.2 48 BULK-d9d9bfe4
12655 Bulk Product c0f616ec Clothing $453.12 429 3.2 10 BULK-b387741d
12656 Bulk Product 115ac6c0 Books $35.10 493 0.2 58 BULK-f5a3b219
12657 Bulk Product dd895b50 Books $372.46 3 0.9 84 BULK-57ac155e
12658 Bulk Product bb9ef0ab Home & Garden $109.66 307 3.5 93 BULK-c72ff4f4
12659 Bulk Product 2b940fb6 Toys & Games $825.08 185 0.7 14 BULK-65049144
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