Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

25 ms

Page Size

25

Current Page

730 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 730 Results Showing 18226 - 18250 of 24441

ID Name Category Price Stock Rating Reviews SKU
18785 Bulk Product 595ea47f Toys & Games $562.37 445 3.1 31 BULK-7ee042eb
18786 Bulk Product 32f2b99b Toys & Games $991.15 352 1.4 19 BULK-d3ac0ad6
18787 Bulk Product 2059aace Clothing $366.56 417 1.0 91 BULK-c87e3b78
18788 Bulk Product 7ff3329f Electronics $57.59 94 4.3 78 BULK-cf8d6eb9
18789 Bulk Product 86f86afb Home & Garden $786.43 338 0.9 17 BULK-9ddc5dfa
18790 Bulk Product b1d0f5ea Home & Garden $446.42 310 4.7 83 BULK-3a9b55aa
18791 Bulk Product 269598a1 Toys & Games $254.76 148 2.3 20 BULK-f05db03f
18792 Bulk Product 970fab09 Electronics $279.22 377 0.1 74 BULK-1b9eec4b
18793 Bulk Product 7643b6af Toys & Games $672.69 209 1.5 98 BULK-3b2c2969
18794 Bulk Product 0da54b0c Clothing $725.10 11 1.7 27 BULK-aaa713c6
18795 Bulk Product 6280593e Home & Garden $156.40 207 4.3 25 BULK-2d2e8608
18796 Bulk Product ca88ec05 Toys & Games $383.91 275 1.1 1 BULK-f4af1fe2
18797 Bulk Product bf7ddaba Electronics $738.57 204 3.0 71 BULK-9606d035
18798 Bulk Product fb03aa04 Toys & Games $748.51 3 4.3 97 BULK-8f0e8f62
18799 Bulk Product 1f3b64d2 Toys & Games $821.19 306 3.7 99 BULK-1cc3b328
18800 Bulk Product bff03c28 Home & Garden $147.41 386 2.9 35 BULK-13436b55
18801 Bulk Product 0c51ed8e Clothing $928.85 384 1.3 18 BULK-8c246333
18802 Bulk Product ad20b8f3 Electronics $258.41 327 0.2 19 BULK-ac0baf1e
18803 Bulk Product 8a7048cd Sports & Outdoors $407.39 358 0.8 78 BULK-3b5b7a2d
18804 Bulk Product cc6fea46 Clothing $770.79 44 0.0 66 BULK-58b6b5e5
18805 Bulk Product 5159b8d8 Home & Garden $956.78 198 3.8 85 BULK-8cfda243
18806 Bulk Product 936343f1 Sports & Outdoors $450.37 443 4.6 93 BULK-d176ec7f
18807 Bulk Product e3c9bc60 Electronics $877.32 481 1.0 52 BULK-e6ada4ac
18808 Bulk Product 90abaa95 Home & Garden $44.27 420 2.8 63 BULK-a3b2d7ad
18809 Bulk Product 093438c1 Electronics $654.77 106 3.2 48 BULK-48e618a5
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