Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

53 ms

Page Size

25

Current Page

699 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 699 Results Showing 17451 - 17475 of 24441

ID Name Category Price Stock Rating Reviews SKU
18010 Bulk Product 12c3f46f Electronics $443.77 192 4.0 34 BULK-237cb8e6
18011 Bulk Product 26780e33 Electronics $312.74 100 1.1 52 BULK-30c25200
18012 Bulk Product d6b4702f Books $582.19 238 2.6 70 BULK-1eaf1c3b
18013 Bulk Product 45e74f91 Sports & Outdoors $225.49 333 2.0 15 BULK-e09f6098
18014 Bulk Product 5dfd5ffb Books $663.17 417 1.9 49 BULK-1f851194
18015 Bulk Product fa4b45c2 Sports & Outdoors $922.93 50 1.7 58 BULK-4af9ccb4
18016 Bulk Product 5174e5d2 Home & Garden $364.76 169 2.5 76 BULK-bba12b79
18017 Bulk Product ac9c760c Sports & Outdoors $752.13 252 4.1 21 BULK-cc8e8de6
18018 Bulk Product 7b5b6f78 Electronics $968.84 450 4.1 81 BULK-ef3912f2
18019 Bulk Product e63b0fd1 Electronics $77.42 262 3.5 17 BULK-704f4027
18020 Bulk Product fd2ea4bf Clothing $998.95 10 2.6 77 BULK-936fc445
18021 Bulk Product 56f01994 Toys & Games $608.81 396 4.3 1 BULK-4dd9ef6e
18022 Bulk Product 3e0bbfbe Electronics $10.43 457 3.7 71 BULK-ded4b0a4
18023 Bulk Product 9a9276cf Books $186.79 29 1.2 60 BULK-389ba372
18024 Bulk Product 0828f932 Clothing $258.96 314 2.3 67 BULK-d262245a
18025 Bulk Product 12ecf354 Clothing $557.28 168 4.5 7 BULK-feb8bd65
18026 Bulk Product c7909a67 Toys & Games $887.10 229 4.2 13 BULK-a068796e
18027 Bulk Product 4c564976 Books $989.29 388 1.9 62 BULK-b15924ad
18028 Bulk Product 897931f5 Sports & Outdoors $948.89 41 0.9 98 BULK-32f1ff56
18029 Bulk Product 31dab05f Electronics $517.91 148 3.7 20 BULK-fb14296f
18030 Bulk Product cfef0fb3 Sports & Outdoors $622.56 56 1.0 6 BULK-e14e59c6
18031 Bulk Product cee31ae1 Electronics $374.95 254 2.2 87 BULK-36a7c152
18032 Bulk Product 8e861659 Home & Garden $899.04 431 2.2 82 BULK-47d6f750
18033 Bulk Product 0d94d758 Sports & Outdoors $761.58 164 3.0 84 BULK-a8dcd510
18034 Bulk Product dc1b80f2 Books $267.06 264 4.5 75 BULK-3a6343a3
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