Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

549 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 549 Results Showing 13701 - 13725 of 24441

ID Name Category Price Stock Rating Reviews SKU
14260 Bulk Product 40cabeba Toys & Games $994.26 327 2.7 26 BULK-948fff0e
14261 Bulk Product c9c208eb Electronics $32.72 139 0.6 48 BULK-a6defb54
14262 Bulk Product 755e5b2f Electronics $372.26 495 4.0 81 BULK-6745fbd0
14263 Bulk Product 5f7d9ae0 Home & Garden $188.42 176 0.8 88 BULK-9ddf3a15
14264 Bulk Product 2bee970d Toys & Games $533.80 307 2.5 48 BULK-e0a6022a
14265 Bulk Product 44b030ff Clothing $148.23 166 1.3 89 BULK-6a4cca8d
14266 Bulk Product ee40cc1d Sports & Outdoors $423.35 333 1.7 33 BULK-b7c90fb3
14267 Bulk Product 144134c3 Clothing $235.36 377 4.3 7 BULK-17809990
14268 Bulk Product da23c0c3 Books $637.49 144 2.5 53 BULK-3c964d6a
14269 Bulk Product 34603927 Sports & Outdoors $571.21 140 2.5 27 BULK-0fb30b5f
14270 Bulk Product c3271d41 Electronics $147.99 350 3.6 22 BULK-470a972e
14271 Bulk Product d3cb6f25 Books $563.50 146 3.3 96 BULK-14f3b075
14272 Bulk Product 6a1f221d Sports & Outdoors $119.99 80 3.7 65 BULK-f8e3d4c3
14273 Bulk Product 7adaf32c Electronics $702.52 61 1.7 93 BULK-373f2271
14274 Bulk Product 54612f77 Sports & Outdoors $889.76 154 3.9 65 BULK-8317aca4
14275 Bulk Product cb17d398 Clothing $594.17 119 0.1 98 BULK-7ac32c1a
14276 Bulk Product 90ede055 Clothing $430.52 244 4.4 63 BULK-8234eb02
14277 Bulk Product d37b581d Sports & Outdoors $437.03 381 4.4 39 BULK-a132dd6a
14278 Bulk Product 445a6deb Toys & Games $146.25 162 4.8 97 BULK-a2c23375
14279 Bulk Product f7a0e0a2 Clothing $290.62 234 3.6 63 BULK-e1c40c2b
14280 Bulk Product 34c1ce71 Sports & Outdoors $711.11 290 3.4 62 BULK-3e70c759
14281 Bulk Product 40895c11 Home & Garden $515.62 376 0.5 22 BULK-70241d70
14282 Bulk Product fef657d2 Electronics $547.91 283 1.0 2 BULK-c06d622c
14283 Bulk Product ed09dabf Sports & Outdoors $147.41 256 2.9 83 BULK-5f7a7528
14284 Bulk Product 31c13237 Home & Garden $455.32 376 1.0 71 BULK-c9c6c11b
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