Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

25

Current Page

842 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 842 Results Showing 21026 - 21050 of 24441

ID Name Category Price Stock Rating Reviews SKU
21585 Bulk Product e8295dd9 Books $490.06 380 4.1 54 BULK-fb6b7159
21586 Bulk Product 7285dd06 Electronics $844.01 232 4.4 32 BULK-ceaa6431
21587 Bulk Product 76d4aa18 Books $633.09 246 3.3 98 BULK-545da763
21588 Bulk Product 64a0c70b Home & Garden $25.87 74 1.2 54 BULK-d80d09be
21589 Bulk Product 95d9e2a9 Electronics $969.30 82 0.3 64 BULK-67ba6182
21590 Bulk Product 602b8b1a Toys & Games $917.31 9 1.1 89 BULK-ffe0de52
21591 Bulk Product b306b129 Books $735.64 341 4.8 53 BULK-9e1656a9
21592 Bulk Product e3cfc5e9 Books $622.01 263 4.7 87 BULK-744e816a
21593 Bulk Product f764e42f Books $335.94 111 2.2 74 BULK-7ebd0959
21594 Bulk Product 1f293514 Electronics $948.33 378 0.2 8 BULK-4bbc1dd7
21595 Bulk Product 76c957b3 Books $404.74 42 2.2 4 BULK-b30eda57
21596 Bulk Product 67474e38 Toys & Games $620.19 330 2.3 25 BULK-7a297618
21597 Bulk Product 2cc467d4 Clothing $594.51 149 1.3 5 BULK-014e3228
21598 Bulk Product 0790aeab Toys & Games $109.25 130 4.3 34 BULK-44253c84
21599 Bulk Product 5c1f638b Clothing $244.74 113 1.1 28 BULK-25231ace
21600 Bulk Product 43e7756f Clothing $420.66 185 2.1 65 BULK-24ee9f67
21601 Bulk Product 0ebbb6e1 Home & Garden $634.87 240 3.1 53 BULK-c35fb818
21602 Bulk Product e911a791 Sports & Outdoors $185.18 301 1.0 63 BULK-e1a015c3
21603 Bulk Product 7da9cb67 Electronics $649.78 84 2.1 86 BULK-66e92d54
21604 Bulk Product 1ebd89bc Clothing $565.15 368 4.5 20 BULK-908d2a4f
21605 Bulk Product 3e058ccf Sports & Outdoors $357.92 22 0.8 87 BULK-171369a3
21606 Bulk Product e65d9266 Books $22.71 447 3.3 72 BULK-f46be294
21607 Bulk Product eb402c3a Clothing $868.95 185 2.5 65 BULK-e45bfaf7
21608 Bulk Product 80c261f8 Electronics $586.11 497 1.3 78 BULK-e0528fcd
21609 Bulk Product efaf9dae Clothing $792.45 51 4.2 89 BULK-e839d1d8
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