Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

290 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 290 Results Showing 7226 - 7250 of 24441

ID Name Category Price Stock Rating Reviews SKU
7785 Bulk Product cd4abc79 Toys & Games $550.61 182 0.9 91 BULK-09e9d1ca
7786 Bulk Product 2cea3033 Books $55.98 134 0.3 74 BULK-2a66f00b
7787 Bulk Product b6d3994e Electronics $605.44 416 1.4 65 BULK-62fca766
7788 Bulk Product 1b2f6020 Electronics $368.04 372 0.5 79 BULK-a46c6c82
7789 Bulk Product be700fb0 Sports & Outdoors $842.61 479 2.4 76 BULK-bfb88b98
7790 Bulk Product a90ff0c2 Toys & Games $445.70 143 3.7 6 BULK-fe1d0c1e
7791 Bulk Product f1740f17 Books $779.16 140 2.0 97 BULK-0e51c8a9
7792 Bulk Product a88761d4 Electronics $689.48 146 3.3 67 BULK-32965ce3
7793 Bulk Product 9c24fefe Electronics $721.44 434 3.0 88 BULK-65f29d5a
7794 Bulk Product 3e4dcffb Home & Garden $339.18 364 1.2 89 BULK-5dba092f
7795 Bulk Product 2b4fc7f0 Electronics $757.47 412 2.3 93 BULK-345c3fc6
7796 Bulk Product 0a66b2e6 Electronics $162.80 86 1.3 8 BULK-4713aef4
7797 Bulk Product 01859025 Sports & Outdoors $923.09 440 3.4 19 BULK-49059047
7798 Bulk Product 00cbd292 Home & Garden $650.25 12 3.1 99 BULK-3f5e31c1
7799 Bulk Product 25e3a369 Clothing $68.20 245 3.6 75 BULK-56630531
7800 Bulk Product 8dabf52e Sports & Outdoors $498.31 104 3.6 77 BULK-dbbb62b3
7801 Bulk Product 28cc6050 Electronics $679.03 484 1.6 96 BULK-1bf18d30
7802 Bulk Product 32c1b524 Books $111.24 458 3.6 84 BULK-cfb64fc6
7803 Bulk Product 2e5fe2aa Home & Garden $616.95 159 4.7 31 BULK-c649c65e
7804 Bulk Product abd72ecd Electronics $779.05 10 2.3 42 BULK-6a65702b
7805 Bulk Product 8dbf6693 Sports & Outdoors $921.43 357 0.1 52 BULK-516edc8d
7806 Bulk Product 636f2d8c Clothing $359.13 254 1.2 2 BULK-ad69d098
7807 Bulk Product bad06fc3 Clothing $81.26 303 3.8 26 BULK-4c8c0381
7808 Bulk Product bc3c6585 Toys & Games $42.00 363 0.6 75 BULK-4429bfd6
7809 Bulk Product 9423ef8e Books $637.86 369 0.8 17 BULK-7e9dd537
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