Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

900 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 900 Results Showing 22476 - 22500 of 24441

ID Name Category Price Stock Rating Reviews SKU
23035 Bulk Product c2f98a6f Electronics $728.13 66 2.1 33 BULK-af5bf0e2
23036 Bulk Product 59b5edc0 Home & Garden $295.44 326 1.9 64 BULK-41c394cd
23037 Bulk Product 4aa6bc5f Clothing $785.76 110 2.1 37 BULK-20130544
23038 Bulk Product 2aad1ebd Home & Garden $257.58 141 2.2 61 BULK-e9704886
23039 Bulk Product 366e499a Electronics $413.96 61 5.0 52 BULK-1c1d91d7
23040 Bulk Product 0aabccec Books $420.39 197 4.0 13 BULK-c444cc66
23041 Bulk Product 71ae5cb9 Electronics $877.04 277 4.7 91 BULK-7e89d0eb
23042 Bulk Product 0abf43ab Toys & Games $164.73 487 3.2 30 BULK-87f455ce
23043 Bulk Product e8bb119d Home & Garden $178.85 119 1.7 50 BULK-f40120e7
23044 Bulk Product c8258812 Toys & Games $556.40 57 2.3 56 BULK-f28d6658
23045 Bulk Product 23219a84 Clothing $647.67 304 4.2 79 BULK-5ad31afb
23046 Bulk Product 9466051a Home & Garden $326.39 32 3.2 76 BULK-2e89b128
23047 Bulk Product e78d79f0 Books $797.18 170 4.0 13 BULK-dce6975e
23048 Bulk Product 3dd53898 Toys & Games $249.53 78 1.4 39 BULK-fbdb8013
23049 Bulk Product 23ccc14a Electronics $146.14 364 0.3 49 BULK-9bfd078c
23050 Bulk Product ce6b0707 Books $496.61 273 0.1 2 BULK-a876bf00
23051 Bulk Product a2692ba7 Books $883.65 340 0.0 86 BULK-ba3c19f5
23052 Bulk Product b1f812cc Clothing $291.84 293 0.3 34 BULK-064f6b44
23053 Bulk Product ed874e29 Clothing $494.36 102 2.1 71 BULK-d6b28a06
23054 Bulk Product 8bd4cda4 Books $57.93 46 0.6 35 BULK-1d7fb608
23055 Bulk Product ece434b0 Electronics $517.26 379 3.8 38 BULK-8e6e666f
23056 Bulk Product c7163fc5 Clothing $474.82 245 1.0 82 BULK-7a5bbc74
23057 Bulk Product 63e47941 Books $530.40 145 4.7 43 BULK-8e80230f
23058 Bulk Product 8a8314b9 Home & Garden $727.31 86 1.8 58 BULK-18a752b4
23059 Bulk Product ade0706b Sports & Outdoors $833.43 195 0.2 84 BULK-e2c484ca
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