Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

25 ms

Page Size

25

Current Page

812 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 812 Results Showing 20276 - 20300 of 24441

ID Name Category Price Stock Rating Reviews SKU
20835 Bulk Product 94e2f991 Clothing $719.05 370 1.9 59 BULK-9bfc28df
20836 Bulk Product 28d6ae2d Clothing $88.79 134 0.4 58 BULK-dfb7f55c
20837 Bulk Product d8bd1f89 Home & Garden $842.80 259 4.4 89 BULK-431c4cb0
20838 Bulk Product 2c99b42b Clothing $593.22 92 4.0 50 BULK-4642f204
20839 Bulk Product 8a7eecac Toys & Games $196.05 241 1.2 54 BULK-367dba44
20840 Bulk Product fb3d7ea9 Clothing $791.23 288 3.5 3 BULK-0f9b3114
20841 Bulk Product b6cfc84c Clothing $906.53 269 4.8 33 BULK-4aae984b
20842 Bulk Product bcb048da Toys & Games $144.91 334 1.6 20 BULK-1b8595ef
20843 Bulk Product 6f26c0ef Toys & Games $818.05 135 3.4 13 BULK-1b5b3767
20844 Bulk Product a4a52639 Clothing $974.65 46 0.4 79 BULK-c3b8ef3b
20845 Bulk Product 968440b7 Sports & Outdoors $555.85 412 1.8 63 BULK-da49ddd3
20846 Bulk Product 0d68d525 Toys & Games $797.24 44 2.1 31 BULK-82ee60b5
20847 Bulk Product ded893ac Toys & Games $215.87 123 1.1 43 BULK-1d95a03f
20848 Bulk Product 52a2d26e Home & Garden $743.47 309 3.1 97 BULK-1c067d52
20849 Bulk Product fe55ea04 Clothing $276.17 496 3.6 30 BULK-9690beab
20850 Bulk Product ba44c3d5 Clothing $761.55 400 1.3 37 BULK-96d29cce
20851 Bulk Product b5638d5d Toys & Games $278.85 480 1.2 75 BULK-22b3d299
20852 Bulk Product fd06c489 Electronics $504.05 293 4.6 73 BULK-961c4abb
20853 Bulk Product e3d2c942 Home & Garden $532.20 188 0.5 14 BULK-12e5873e
20854 Bulk Product 7bd91e9c Home & Garden $234.41 485 0.1 11 BULK-922369fc
20855 Bulk Product 56ab8abd Electronics $844.97 17 1.6 3 BULK-051b9724
20856 Bulk Product d4294343 Electronics $571.55 139 0.7 18 BULK-9667a859
20857 Bulk Product 4dae46a4 Toys & Games $21.18 389 3.2 44 BULK-a65fc190
20858 Bulk Product 6be5b19f Books $422.09 82 1.8 47 BULK-c7a1fa30
20859 Bulk Product 5134cf8f Home & Garden $833.23 350 0.3 47 BULK-b0cc261a
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