Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

643 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 643 Results Showing 16051 - 16075 of 24441

ID Name Category Price Stock Rating Reviews SKU
16610 Bulk Product 282c3238 Clothing $795.39 359 3.9 70 BULK-838842a4
16611 Bulk Product 31784b44 Toys & Games $659.02 372 3.4 93 BULK-1b3a1644
16612 Bulk Product 3a8dce48 Toys & Games $808.62 283 1.6 35 BULK-1d3263c9
16613 Bulk Product 77bac2ad Electronics $753.51 167 2.7 12 BULK-6b358b2f
16614 Bulk Product 0c6ba7cf Toys & Games $331.99 113 1.3 18 BULK-33f45362
16615 Bulk Product ac1cb61e Clothing $572.16 36 2.9 31 BULK-f9ca91e9
16616 Bulk Product 5326ac64 Clothing $495.34 373 3.7 45 BULK-6fc77a70
16617 Bulk Product 8de771d1 Electronics $241.46 299 2.8 26 BULK-dee36385
16618 Bulk Product 13f148d2 Books $1,004.68 254 2.8 52 BULK-61e78fed
16619 Bulk Product 22426b7e Clothing $605.10 289 4.9 48 BULK-4886b53b
16620 Bulk Product 8f8a8cb4 Books $666.66 254 1.9 71 BULK-2ad02b62
16621 Bulk Product 7249e045 Toys & Games $870.90 340 0.7 35 BULK-09dd90c1
16622 Bulk Product f0c706cb Home & Garden $976.74 241 4.7 81 BULK-1104385e
16623 Bulk Product daf8fd09 Sports & Outdoors $218.44 277 4.4 40 BULK-4cd24d14
16624 Bulk Product 63650a03 Home & Garden $526.18 64 0.7 55 BULK-4a5af0c9
16625 Bulk Product 0ac0bb55 Sports & Outdoors $393.13 169 1.3 42 BULK-82570eef
16626 Bulk Product e285d055 Sports & Outdoors $830.30 312 4.4 14 BULK-331a9fe3
16627 Bulk Product 5ed5ace7 Books $663.83 264 1.5 40 BULK-6b130211
16628 Bulk Product 073dadb6 Home & Garden $278.65 12 3.6 32 BULK-958c4d9d
16629 Bulk Product 79ff558f Clothing $945.75 28 0.3 20 BULK-27dbf291
16630 Bulk Product 31476f38 Home & Garden $25.68 352 0.1 81 BULK-f5682e46
16631 Bulk Product 1b4c8956 Electronics $603.53 19 4.4 87 BULK-fa15b365
16632 Bulk Product 7cc0b9b3 Clothing $425.21 152 4.5 91 BULK-dbe262f9
16633 Bulk Product 85fb0848 Toys & Games $883.22 191 2.9 81 BULK-f132a6fd
16634 Bulk Product 6ff10e60 Electronics $712.80 239 3.2 55 BULK-0c93034e
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