Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

64 ms

Page Size

25

Current Page

445 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 445 Results Showing 11101 - 11125 of 24441

ID Name Category Price Stock Rating Reviews SKU
11660 Bulk Product c2b04e5c Home & Garden $1,005.96 22 2.4 76 BULK-0acdc5b6
11661 Bulk Product 1a46af2b Books $526.30 287 4.6 0 BULK-e6409e74
11662 Bulk Product 4c020769 Electronics $269.45 249 4.9 68 BULK-ca7d4ebb
11663 Bulk Product 33b88293 Toys & Games $974.25 203 0.4 98 BULK-b7d59d5d
11664 Bulk Product d62782b4 Toys & Games $794.16 36 2.6 47 BULK-9c4d731b
11665 Bulk Product 27a9a3a8 Clothing $745.12 337 4.5 37 BULK-483daf29
11666 Bulk Product bcd64972 Books $567.53 308 1.5 40 BULK-99f4aaf8
11667 Bulk Product 45e95cb7 Sports & Outdoors $206.42 60 4.9 29 BULK-9413f0cd
11668 Bulk Product 7df2970a Clothing $96.22 19 2.3 76 BULK-e58c1be5
11669 Bulk Product 2c210a23 Electronics $970.63 498 2.9 87 BULK-abe8126d
11670 Bulk Product 0bb5bc8e Toys & Games $996.52 143 0.4 20 BULK-99a889c4
11671 Bulk Product e59883fc Sports & Outdoors $536.98 20 2.1 64 BULK-da853635
11672 Bulk Product dda41792 Books $447.61 475 0.8 94 BULK-138e8448
11673 Bulk Product 02165a4b Electronics $254.41 349 3.2 43 BULK-caef8004
11674 Bulk Product 81eeea97 Toys & Games $540.14 105 0.4 77 BULK-8d625625
11675 Bulk Product e961bcd7 Books $793.22 389 4.4 18 BULK-1d14c922
11676 Bulk Product 81d38d7c Clothing $761.10 246 0.4 33 BULK-c62e3d95
11677 Bulk Product b5bb9a46 Home & Garden $191.71 178 4.3 63 BULK-ed8c8c46
11678 Bulk Product a7f5a69e Clothing $647.03 478 2.1 80 BULK-0f35be91
11679 Bulk Product a6044241 Clothing $579.13 479 0.8 5 BULK-565397fe
11680 Bulk Product f9c5f87b Books $991.73 254 4.5 74 BULK-d39196fc
11681 Bulk Product 3416c1d6 Electronics $882.75 359 0.6 18 BULK-6e16440a
11682 Bulk Product ac8ad48f Home & Garden $663.94 132 2.6 54 BULK-cb6d0a52
11683 Bulk Product af8600b0 Electronics $290.73 343 3.4 69 BULK-4dd69413
11684 Bulk Product 1306f65a Clothing $610.46 245 1.2 27 BULK-feb89359
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