Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

745 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 745 Results Showing 18601 - 18625 of 24441

ID Name Category Price Stock Rating Reviews SKU
19160 Bulk Product 6663aba8 Sports & Outdoors $1,009.34 213 4.5 54 BULK-4cd554cf
19161 Bulk Product f51078f4 Sports & Outdoors $865.37 283 1.7 60 BULK-7f53d94d
19162 Bulk Product d6d20a28 Electronics $655.39 465 1.7 13 BULK-dfee0a9b
19163 Bulk Product 789f3f03 Sports & Outdoors $632.42 275 3.1 21 BULK-81e0bad9
19164 Bulk Product c3bc69ce Books $216.65 305 2.2 14 BULK-17e64586
19165 Bulk Product ffd24652 Toys & Games $570.00 192 0.9 92 BULK-1a9cce7f
19166 Bulk Product eace542e Sports & Outdoors $81.10 159 5.0 16 BULK-f155ad87
19167 Bulk Product 53c08d8c Toys & Games $584.71 332 0.8 17 BULK-35c3f5cf
19168 Bulk Product a12e3aad Sports & Outdoors $598.55 206 2.8 67 BULK-ac832bba
19169 Bulk Product 39ef237a Sports & Outdoors $281.44 361 0.5 91 BULK-6cbf2266
19170 Bulk Product 47e32f80 Clothing $726.06 481 4.7 15 BULK-e8d1a262
19171 Bulk Product 939b8376 Clothing $817.11 306 3.9 64 BULK-6d319e69
19172 Bulk Product f7b7502e Books $616.64 447 4.7 20 BULK-caff5e0c
19173 Bulk Product 7336de9c Home & Garden $907.51 425 4.1 46 BULK-684689ad
19174 Bulk Product a334ae6c Toys & Games $421.81 416 1.4 88 BULK-c90497ce
19175 Bulk Product f7be22db Electronics $621.63 298 4.5 78 BULK-f9971ac3
19176 Bulk Product 0f3930bd Toys & Games $703.05 380 3.3 18 BULK-613fbe41
19177 Bulk Product a991e702 Books $466.36 222 2.6 5 BULK-241948bd
19178 Bulk Product ba273c73 Home & Garden $327.48 295 2.8 9 BULK-788e0c69
19179 Bulk Product 3078d6da Electronics $259.22 301 0.7 93 BULK-64d1c799
19180 Bulk Product 8b05876d Clothing $135.49 417 4.2 73 BULK-5e784e7a
19181 Bulk Product 2a46b611 Home & Garden $102.08 313 1.1 64 BULK-2e333dae
19182 Bulk Product 18ffc78b Books $266.90 398 0.1 13 BULK-c383d56e
19183 Bulk Product 1a7e8531 Sports & Outdoors $591.14 17 3.9 53 BULK-67f8c62b
19184 Bulk Product b0c9861a Clothing $709.55 353 2.6 59 BULK-83450398
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