Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

396 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 396 Results Showing 9876 - 9900 of 24441

ID Name Category Price Stock Rating Reviews SKU
10435 Bulk Product bc65d700 Clothing $636.85 375 3.0 7 BULK-a3aef224
10436 Bulk Product 03b31533 Toys & Games $725.56 195 3.2 73 BULK-e7f53caa
10437 Bulk Product bb66d8d5 Electronics $143.05 394 0.8 59 BULK-7f5f3bc8
10438 Bulk Product 32da064e Books $882.57 108 4.7 79 BULK-d4e25bbd
10439 Bulk Product d129b9cf Home & Garden $659.49 67 0.5 40 BULK-7d37a4f5
10440 Bulk Product 0df0add9 Toys & Games $206.96 476 1.0 29 BULK-2e61f830
10441 Bulk Product 039bf4a4 Clothing $638.32 106 4.9 61 BULK-b920d1a0
10442 Bulk Product 44f54cbe Clothing $680.25 400 3.0 5 BULK-99d1f754
10443 Bulk Product f0a571cc Home & Garden $775.96 399 3.0 40 BULK-4ebd2665
10444 Bulk Product e00a5613 Clothing $241.65 139 0.5 44 BULK-2c6c606a
10445 Bulk Product 279e9c5a Toys & Games $620.94 382 0.9 83 BULK-493a852e
10446 Bulk Product 98b4250e Clothing $443.59 488 3.9 98 BULK-55231ee6
10447 Bulk Product 38602a09 Books $846.92 326 2.6 14 BULK-b9fe8b9f
10448 Bulk Product 4e781488 Toys & Games $1,004.28 110 4.8 41 BULK-65efe7d4
10449 Bulk Product 6d64f5fb Electronics $877.18 409 1.4 34 BULK-da78b728
10450 Bulk Product 5bee1d5b Electronics $317.83 104 3.9 21 BULK-003e4a66
10451 Bulk Product a997f9bf Home & Garden $243.96 265 1.6 96 BULK-f55f934a
10452 Bulk Product c88d373e Sports & Outdoors $758.81 107 4.9 37 BULK-b592b76c
10453 Bulk Product 46d88a7b Electronics $314.20 38 3.1 8 BULK-35ba93ce
10454 Bulk Product bfd33794 Electronics $877.30 302 2.1 55 BULK-bff34a95
10455 Bulk Product 5c48f291 Books $267.05 322 0.8 74 BULK-7adecb72
10456 Bulk Product addbb9ed Clothing $12.05 483 1.5 90 BULK-cc2bbef0
10457 Bulk Product 900f70ef Clothing $475.75 137 2.7 11 BULK-9008abc2
10458 Bulk Product cffc9d22 Clothing $189.45 392 2.6 61 BULK-d724af60
10459 Bulk Product a827291d Toys & Games $395.89 124 3.7 15 BULK-f449afeb
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