Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

407 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 407 Results Showing 10151 - 10175 of 24441

ID Name Category Price Stock Rating Reviews SKU
10710 Bulk Product 4ed74006 Electronics $165.35 152 1.3 7 BULK-217000c5
10711 Bulk Product 1c78fe15 Books $435.17 36 3.7 74 BULK-68040256
10712 Bulk Product 6a9582e8 Toys & Games $260.79 300 4.0 59 BULK-eef24bd0
10713 Bulk Product c4da1497 Sports & Outdoors $685.96 368 4.3 49 BULK-41042761
10714 Bulk Product 7d4756ef Home & Garden $466.59 31 2.1 0 BULK-cb6e9410
10715 Bulk Product 1aadb633 Books $737.30 104 3.3 21 BULK-8896fa8e
10716 Bulk Product ff183b2c Clothing $105.52 400 1.3 76 BULK-21e1851d
10717 Bulk Product 1025dcb4 Books $337.73 134 3.5 11 BULK-1ed57204
10718 Bulk Product e5c03d19 Sports & Outdoors $1,001.55 241 1.7 0 BULK-1d6831f7
10719 Bulk Product e4042a53 Home & Garden $966.12 248 1.5 61 BULK-6be56c3d
10720 Bulk Product 8cf72086 Toys & Games $26.57 182 4.4 54 BULK-818619cc
10721 Bulk Product 42505b27 Clothing $872.32 139 2.1 74 BULK-cc6d70c5
10722 Bulk Product 51c669e2 Electronics $234.94 429 2.6 54 BULK-fb3efb31
10723 Bulk Product 47017ff0 Toys & Games $479.71 127 4.5 10 BULK-96ef93c2
10724 Bulk Product 1db8eff4 Toys & Games $889.65 294 4.9 69 BULK-952917aa
10725 Bulk Product da8de844 Electronics $537.87 332 4.2 83 BULK-6e11481a
10726 Bulk Product b27318d1 Clothing $988.01 456 0.2 6 BULK-8b101070
10727 Bulk Product 20577a1b Clothing $358.02 92 4.4 30 BULK-ef317ed2
10728 Bulk Product 977efce7 Toys & Games $748.02 308 0.6 36 BULK-3a69a0bc
10729 Bulk Product 8fabdb4c Home & Garden $641.60 478 0.6 30 BULK-9f521bb2
10730 Bulk Product d4fe605a Toys & Games $715.01 138 1.5 12 BULK-1b360803
10731 Bulk Product e67bd565 Home & Garden $290.88 345 4.3 92 BULK-89dbbfaf
10732 Bulk Product 0726d733 Electronics $405.65 454 3.4 29 BULK-a8248b3d
10733 Bulk Product f0e9b2b0 Toys & Games $619.29 291 4.0 57 BULK-94de391d
10734 Bulk Product a727073a Books $577.63 306 4.9 66 BULK-b9877d65
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