Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

788 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 788 Results Showing 19676 - 19700 of 24441

ID Name Category Price Stock Rating Reviews SKU
20235 Bulk Product 96cb965e Electronics $911.01 320 3.1 88 BULK-4cf68e69
20236 Bulk Product eb498b7a Clothing $283.13 5 0.3 67 BULK-b672978e
20237 Bulk Product aca92cbd Clothing $461.18 311 2.8 11 BULK-ed707f33
20238 Bulk Product 9ef5249d Clothing $862.28 265 3.2 49 BULK-6538d6c9
20239 Bulk Product dfb5c3cb Toys & Games $741.06 72 1.8 56 BULK-91a1c281
20240 Bulk Product 96ddd4f8 Home & Garden $24.88 334 3.1 59 BULK-219dcde9
20241 Bulk Product 6efc204d Toys & Games $75.58 9 1.4 19 BULK-030f803e
20242 Bulk Product 521c492e Books $742.28 111 0.4 98 BULK-25fd15fc
20243 Bulk Product 50065269 Sports & Outdoors $369.88 489 1.0 99 BULK-07818b05
20244 Bulk Product 9bf326a3 Books $462.37 294 3.0 51 BULK-4a0bdc0a
20245 Bulk Product 0a8c6697 Books $230.20 148 4.6 93 BULK-74d7b59f
20246 Bulk Product 5e6658d1 Electronics $781.48 103 2.8 39 BULK-454e0bf1
20247 Bulk Product 70be9ff5 Books $363.16 307 1.7 4 BULK-1efa695c
20248 Bulk Product 86fd3473 Books $90.30 430 1.0 60 BULK-7674a40d
20249 Bulk Product e7e81d82 Sports & Outdoors $412.79 211 1.5 18 BULK-34d88d0d
20250 Bulk Product 9d8ff992 Clothing $606.35 63 4.0 40 BULK-23afc0d1
20251 Bulk Product 9270d79c Sports & Outdoors $327.11 321 0.2 72 BULK-ade83627
20252 Bulk Product 5db5eb65 Electronics $879.98 481 4.7 47 BULK-c43a00fb
20253 Bulk Product d390b877 Electronics $117.78 460 2.3 78 BULK-c2851df7
20254 Bulk Product 26be1936 Clothing $191.38 348 2.7 94 BULK-5f752ed1
20255 Bulk Product 9c2631be Clothing $626.71 244 4.1 20 BULK-154ea7af
20256 Bulk Product 9a0153d4 Clothing $135.62 248 2.1 77 BULK-a31012b1
20257 Bulk Product 017fdd4c Sports & Outdoors $843.94 3 4.6 45 BULK-d4aa6edb
20258 Bulk Product 119d2c91 Electronics $514.36 453 2.0 15 BULK-d80b7782
20259 Bulk Product ae711649 Books $601.39 378 4.8 1 BULK-96535081
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