Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

934 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 934 Results Showing 23326 - 23350 of 24441

ID Name Category Price Stock Rating Reviews SKU
23885 Bulk Product 8c929369 Sports & Outdoors $42.14 224 1.5 79 BULK-24b0f727
23886 Bulk Product bd6c0b0e Books $13.96 196 4.6 82 BULK-1904a2fd
23887 Bulk Product 7390f339 Home & Garden $82.89 160 4.6 71 BULK-8cac7335
23888 Bulk Product 31d654f6 Home & Garden $497.79 484 0.4 45 BULK-fb44c9e7
23889 Bulk Product 602b51ef Home & Garden $38.47 248 0.0 1 BULK-0e2a959e
23890 Bulk Product 5d6fd6b5 Home & Garden $816.26 408 3.1 63 BULK-e7edd3ee
23891 Bulk Product 60dc6a85 Home & Garden $186.52 343 4.8 4 BULK-c7473cb8
23892 Bulk Product 24398932 Clothing $438.68 45 2.5 48 BULK-4d7b8a61
23893 Bulk Product 70084763 Clothing $157.50 278 0.3 13 BULK-526d2a92
23894 Bulk Product a02da377 Toys & Games $486.26 346 4.8 16 BULK-ac2fea70
23895 Bulk Product 1bbee93a Electronics $333.80 201 4.0 12 BULK-b6a118e9
23896 Bulk Product 6703e6c1 Toys & Games $1,001.36 239 2.8 94 BULK-3d866b92
23897 Bulk Product 0286a258 Clothing $504.82 253 3.9 35 BULK-b2b9c67f
23898 Bulk Product 7cef4b14 Electronics $841.62 77 4.0 87 BULK-cb1dee70
23899 Bulk Product 6a71293e Electronics $454.63 291 0.3 34 BULK-1231a16e
23900 Bulk Product 55212064 Sports & Outdoors $671.79 388 1.0 2 BULK-3aded461
23901 Bulk Product 29f55875 Sports & Outdoors $14.43 189 2.4 19 BULK-b69f39c8
23902 Bulk Product 485c9541 Clothing $1,005.91 252 3.5 72 BULK-8eb8fc56
23903 Bulk Product c8d3f8d2 Toys & Games $243.24 108 3.7 75 BULK-152f544b
23904 Bulk Product 29dbe94e Books $663.04 475 2.5 13 BULK-1a172ab5
23905 Bulk Product 68fa5ce0 Home & Garden $942.11 191 0.1 69 BULK-0ea11a54
23906 Bulk Product 8e81f1d9 Sports & Outdoors $333.66 21 1.8 10 BULK-5e258af6
23907 Bulk Product 53212904 Home & Garden $351.96 53 2.7 8 BULK-46e75202
23908 Bulk Product ea574b0a Toys & Games $290.43 473 3.0 51 BULK-ffa1bfe7
23909 Bulk Product 5c4eaf09 Home & Garden $203.46 263 2.3 10 BULK-e577718c
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