Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

34 ms

Page Size

25

Current Page

252 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 252 Results Showing 6276 - 6300 of 24441

ID Name Category Price Stock Rating Reviews SKU
6835 Bulk Product 47b5263b Electronics $131.93 36 2.5 5 BULK-63c73f76
6836 Bulk Product 70d1b5af Sports & Outdoors $667.51 435 2.2 8 BULK-5dec1793
6837 Bulk Product d546be2f Electronics $144.96 319 3.4 3 BULK-81b6d904
6838 Bulk Product fffe6dfe Toys & Games $492.76 479 4.4 63 BULK-e6ef073e
6839 Bulk Product 3d6b3363 Home & Garden $126.29 167 3.5 24 BULK-de6ebfe0
6840 Bulk Product 906fa89e Electronics $96.25 169 4.8 75 BULK-741469a2
6841 Bulk Product ccd35da0 Sports & Outdoors $318.91 439 0.5 72 BULK-adcb958a
6842 Bulk Product 7c93f053 Books $262.62 499 4.2 83 BULK-5e76d020
6843 Bulk Product 0c8a00c3 Toys & Games $461.58 418 0.8 11 BULK-d1d83c6c
6844 Bulk Product 56d1bff9 Electronics $642.64 482 3.5 20 BULK-d1d54505
6845 Bulk Product 7e1eb48b Electronics $577.14 488 2.7 12 BULK-8ae88e6e
6846 Bulk Product 89fa9023 Home & Garden $978.30 117 0.1 85 BULK-7f38e59f
6847 Bulk Product fb28a946 Books $586.29 472 2.5 24 BULK-a5ee6a5f
6848 Bulk Product 70e2bdd4 Clothing $519.44 479 2.5 89 BULK-9275969c
6849 Bulk Product acc0f6dd Electronics $883.15 497 2.1 34 BULK-5d051ab7
6850 Bulk Product 834b4d9d Sports & Outdoors $605.05 452 2.8 21 BULK-edaaba7a
6851 Bulk Product 340f5c22 Clothing $133.93 76 2.8 33 BULK-7401bbfd
6852 Bulk Product 08a400e1 Sports & Outdoors $231.10 177 4.5 14 BULK-740619c2
6853 Bulk Product 2b58f633 Sports & Outdoors $371.78 288 2.2 46 BULK-b246d496
6854 Bulk Product 98a62360 Sports & Outdoors $29.46 129 4.9 7 BULK-1224879b
6855 Bulk Product bea195be Books $885.95 323 2.6 6 BULK-afafb0b2
6856 Bulk Product 3b2fe2c9 Books $341.34 443 2.7 31 BULK-7a0ff1e8
6857 Bulk Product 78452ae9 Home & Garden $187.32 329 2.7 60 BULK-d920eb0b
6858 Bulk Product 3f1d1464 Sports & Outdoors $841.74 88 2.0 52 BULK-51914cd9
6859 Bulk Product de5db1dd Electronics $447.49 66 2.9 99 BULK-2e1954d0
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