Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

55 ms

Page Size

25

Current Page

214 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 214 Results Showing 5326 - 5350 of 24441

ID Name Category Price Stock Rating Reviews SKU
5885 Bulk Product 8b58f328 Electronics $112.04 150 1.2 71 BULK-54891d77
5886 Bulk Product 0314bb61 Clothing $555.28 163 0.6 38 BULK-0adf4d8a
5887 Bulk Product 38a551fa Clothing $335.88 240 3.1 31 BULK-b5c68533
5888 Bulk Product 335f9e40 Electronics $391.40 222 3.1 98 BULK-e811bade
5889 Bulk Product 5a6686fa Clothing $736.26 389 0.2 66 BULK-f7228567
5890 Bulk Product af490456 Books $236.38 340 2.5 45 BULK-68f619f9
5891 Bulk Product 502ae8f5 Sports & Outdoors $29.22 200 0.9 64 BULK-5bdd43b2
5892 Bulk Product d71c866b Clothing $465.16 307 1.3 36 BULK-a1de2482
5893 Bulk Product 99d78ef6 Electronics $709.41 335 0.7 77 BULK-31248e29
5894 Bulk Product fbdb8796 Books $419.95 80 3.4 55 BULK-010f18d9
5895 Bulk Product a331227c Electronics $314.25 41 2.8 73 BULK-bec13351
5896 Bulk Product d0204e77 Clothing $114.19 227 1.4 35 BULK-c7eb8388
5897 Bulk Product 257b86dc Toys & Games $596.95 408 0.5 16 BULK-e15f158f
5898 Bulk Product 793fc4b7 Electronics $10.33 155 0.8 15 BULK-ca165ffd
5899 Bulk Product 1c1a309c Electronics $391.86 394 3.4 48 BULK-46d3fd1d
5900 Bulk Product f3a15493 Clothing $40.53 185 2.7 56 BULK-e3bef205
5901 Bulk Product 491c9d25 Books $938.96 421 4.8 56 BULK-d1d02aba
5902 Bulk Product 93916406 Toys & Games $688.71 366 2.8 20 BULK-abf1b2c1
5903 Bulk Product eb8de94b Books $931.74 273 0.7 71 BULK-345185d3
5904 Bulk Product db2b8a62 Electronics $471.70 116 4.6 11 BULK-4924b729
5905 Bulk Product db1257eb Books $591.40 247 0.8 47 BULK-2eee7ecd
5906 Bulk Product 1aa81e02 Sports & Outdoors $260.12 304 2.6 11 BULK-2b5f5d78
5907 Bulk Product bb28310e Books $597.30 16 0.5 60 BULK-a803d817
5908 Bulk Product 19ab7eac Sports & Outdoors $424.46 468 1.3 95 BULK-8df004f0
5909 Bulk Product 92c5c9f5 Books $425.61 125 3.0 7 BULK-b2b6dce3
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