Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

534 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 534 Results Showing 13326 - 13350 of 24441

ID Name Category Price Stock Rating Reviews SKU
13885 Bulk Product c20ef2a2 Toys & Games $873.33 479 3.5 92 BULK-44a1a47c
13886 Bulk Product fc90a8da Electronics $460.24 381 4.3 1 BULK-8c682eda
13887 Bulk Product 48e8d26b Toys & Games $725.48 96 0.4 96 BULK-f816c345
13888 Bulk Product 181da457 Toys & Games $204.31 180 1.0 32 BULK-d04372c6
13889 Bulk Product e33fc251 Home & Garden $407.64 44 0.2 71 BULK-dabb1f94
13890 Bulk Product caa53513 Home & Garden $560.92 466 1.4 17 BULK-28385895
13891 Bulk Product d9dd0be8 Books $404.32 78 1.0 89 BULK-f13e0cc8
13892 Bulk Product 7de42750 Books $749.30 38 0.5 25 BULK-ffc2942f
13893 Bulk Product 714ce970 Electronics $558.79 264 0.2 89 BULK-384ff538
13894 Bulk Product 82cad77b Home & Garden $360.26 62 2.4 6 BULK-99d0b7fe
13895 Bulk Product 1c3dad2a Clothing $486.70 402 1.4 60 BULK-685bb0e1
13896 Bulk Product c62ec527 Books $1,005.56 436 1.4 25 BULK-04a33c1a
13897 Bulk Product 6354fae9 Home & Garden $200.92 165 0.7 2 BULK-dda63b39
13898 Bulk Product 0fce7e7d Home & Garden $205.12 351 1.5 89 BULK-da0ee5b3
13899 Bulk Product c2a3e9f7 Sports & Outdoors $22.29 297 0.2 34 BULK-5a47b26c
13900 Bulk Product bb951751 Home & Garden $391.58 228 3.7 85 BULK-baca8827
13901 Bulk Product ef62b3de Books $410.53 247 2.7 68 BULK-d65a4fd2
13902 Bulk Product 9d3248f7 Home & Garden $248.24 474 1.2 93 BULK-1bdb8b7b
13903 Bulk Product 5ee6774c Sports & Outdoors $920.13 201 3.9 90 BULK-60561060
13904 Bulk Product 895b6c25 Electronics $680.01 205 1.9 42 BULK-69867bd8
13905 Bulk Product daa100b8 Sports & Outdoors $679.22 193 3.1 53 BULK-039cdc71
13906 Bulk Product f96d8e04 Clothing $69.28 438 0.1 2 BULK-d58ff0ff
13907 Bulk Product c2a5cf22 Sports & Outdoors $663.00 281 4.1 41 BULK-922de3c3
13908 Bulk Product f7ada5e3 Sports & Outdoors $750.13 161 3.0 10 BULK-667e2687
13909 Bulk Product 3980b7d9 Home & Garden $55.67 183 3.7 32 BULK-ddc52753
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