Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

551 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 551 Results Showing 13751 - 13775 of 24441

ID Name Category Price Stock Rating Reviews SKU
14310 Bulk Product 2dac6536 Sports & Outdoors $353.84 448 1.6 38 BULK-8112921f
14311 Bulk Product 5c61c718 Electronics $441.71 28 0.7 56 BULK-2edcbb00
14312 Bulk Product 0bf1d8ed Sports & Outdoors $327.90 31 1.6 96 BULK-b4b098a8
14313 Bulk Product 12cc7008 Home & Garden $889.82 331 3.9 67 BULK-2f3300b0
14314 Bulk Product c1983d4d Home & Garden $568.28 277 4.3 64 BULK-f3204830
14315 Bulk Product 2981d1e8 Sports & Outdoors $482.45 36 3.8 31 BULK-9532f564
14316 Bulk Product f5c730d1 Toys & Games $578.54 230 2.5 18 BULK-92571389
14317 Bulk Product 7399f352 Toys & Games $549.57 478 4.9 9 BULK-9e8bcced
14318 Bulk Product b1aba29e Electronics $739.30 465 1.2 69 BULK-8ce770b4
14319 Bulk Product 3ccaf3c5 Home & Garden $344.92 469 0.5 43 BULK-35c64cc6
14320 Bulk Product df3c3a1f Electronics $852.41 19 2.0 25 BULK-c5b6f4e4
14321 Bulk Product dd2888c9 Sports & Outdoors $445.06 371 2.8 87 BULK-167525dd
14322 Bulk Product 3f8024c2 Home & Garden $76.98 150 0.3 34 BULK-7eb66d64
14323 Bulk Product 83462046 Home & Garden $26.68 456 4.0 2 BULK-ffb3b600
14324 Bulk Product 9237a7db Home & Garden $251.20 296 0.2 90 BULK-23a0fcf2
14325 Bulk Product c2f19459 Clothing $965.42 193 4.6 80 BULK-f82a33b5
14326 Bulk Product 28919c83 Books $140.35 100 2.9 50 BULK-200e1d08
14327 Bulk Product cd3ac135 Electronics $857.15 433 4.7 4 BULK-eff6f532
14328 Bulk Product 28dd5d0e Books $209.05 53 2.6 14 BULK-1f73f622
14329 Bulk Product 2e138736 Toys & Games $923.93 436 1.6 45 BULK-23a34831
14330 Bulk Product 79fb51ab Electronics $106.15 317 2.6 57 BULK-131fd7f2
14331 Bulk Product d509047e Home & Garden $14.84 1 0.3 53 BULK-c240fb63
14332 Bulk Product 4e62a670 Books $166.33 203 2.9 86 BULK-4b7a7880
14333 Bulk Product 8723e606 Home & Garden $497.25 76 4.0 1 BULK-92852b43
14334 Bulk Product 956bf2d1 Toys & Games $838.51 464 3.3 32 BULK-8bbd6a2d
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