Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

36 ms

Page Size

25

Current Page

729 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 729 Results Showing 18201 - 18225 of 24441

ID Name Category Price Stock Rating Reviews SKU
18760 Bulk Product 347837c4 Electronics $494.28 379 4.2 81 BULK-79445486
18761 Bulk Product 2e047ff7 Books $187.26 322 1.2 67 BULK-48210d31
18762 Bulk Product bd256936 Sports & Outdoors $63.73 15 4.5 21 BULK-30265aed
18763 Bulk Product 0e7338e5 Toys & Games $878.19 264 3.6 70 BULK-796873b8
18764 Bulk Product 2f68bc1b Electronics $793.33 114 2.4 80 BULK-c248d6c7
18765 Bulk Product 168fd58f Clothing $861.12 355 4.6 94 BULK-b41688a3
18766 Bulk Product 320c5517 Toys & Games $396.91 304 4.7 34 BULK-31e86660
18767 Bulk Product 5452fbb5 Home & Garden $458.43 353 3.0 58 BULK-2e1db2de
18768 Bulk Product 15bb75b3 Sports & Outdoors $251.83 196 1.5 78 BULK-3eab7969
18769 Bulk Product a835aa04 Books $791.56 230 2.4 18 BULK-9c68b11e
18770 Bulk Product 68715ee9 Clothing $875.26 296 2.0 59 BULK-5b4a8ddd
18771 Bulk Product 39d8a2ea Electronics $924.98 20 1.6 19 BULK-cd8e4541
18772 Bulk Product c83f1d6f Clothing $599.73 193 2.0 10 BULK-d9c4f40a
18773 Bulk Product 19455f6f Home & Garden $312.14 188 2.5 88 BULK-abbf9161
18774 Bulk Product 8cd5b198 Books $527.87 472 1.9 93 BULK-b8019145
18775 Bulk Product 3d4f6175 Clothing $884.55 492 4.7 29 BULK-613768a0
18776 Bulk Product e478b5ba Toys & Games $531.17 251 0.0 65 BULK-faf3d417
18777 Bulk Product b973f241 Clothing $314.24 72 4.7 21 BULK-fb7a04e9
18778 Bulk Product e283530a Clothing $854.56 230 0.6 63 BULK-2fade878
18779 Bulk Product dfba99a8 Sports & Outdoors $788.31 16 4.2 62 BULK-717f6c9f
18780 Bulk Product c2f652a1 Electronics $165.69 288 3.4 20 BULK-0386df4d
18781 Bulk Product b4328ae0 Toys & Games $175.70 204 1.6 24 BULK-6dad3ce4
18782 Bulk Product 196825da Electronics $309.60 262 0.7 18 BULK-be886330
18783 Bulk Product 5f2b9e51 Clothing $646.11 427 1.4 92 BULK-21dcac38
18784 Bulk Product 711a36df Sports & Outdoors $935.73 46 0.3 56 BULK-5d1f0d23
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