Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

70 ms

Page Size

25

Current Page

710 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 710 Results Showing 17726 - 17750 of 24441

ID Name Category Price Stock Rating Reviews SKU
18285 Bulk Product 4df4dd4d Clothing $407.32 49 3.2 29 BULK-07f9f2c3
18286 Bulk Product 493b5548 Electronics $994.42 242 4.8 89 BULK-6e888fd3
18287 Bulk Product 713ab995 Clothing $62.59 419 1.9 89 BULK-cc11d8c2
18288 Bulk Product abdff5f0 Sports & Outdoors $174.18 291 0.2 98 BULK-2ea34403
18289 Bulk Product 0f9aeef6 Toys & Games $556.13 389 3.6 46 BULK-72fc05fc
18290 Bulk Product 2afe1e43 Home & Garden $203.13 209 3.1 53 BULK-dc2be9d0
18291 Bulk Product a69e1dc1 Books $687.72 319 0.0 67 BULK-5bf9d6e6
18292 Bulk Product 17ec4691 Home & Garden $595.38 125 1.8 83 BULK-b24d09bc
18293 Bulk Product 37921ac0 Sports & Outdoors $690.70 211 3.2 40 BULK-6e4c308f
18294 Bulk Product a943afeb Clothing $744.42 159 1.0 34 BULK-6b237165
18295 Bulk Product 7e1a7186 Books $596.05 83 1.9 44 BULK-a88e2dd7
18296 Bulk Product d5d151ec Books $92.53 468 1.2 85 BULK-49549c2e
18297 Bulk Product 9ba60c18 Books $745.37 460 3.3 99 BULK-a4706332
18298 Bulk Product e542cbb2 Toys & Games $481.18 297 3.0 91 BULK-48ff3dc4
18299 Bulk Product 1eb8db43 Home & Garden $65.15 129 1.2 31 BULK-54534776
18300 Bulk Product b8c5192f Sports & Outdoors $421.40 197 0.2 42 BULK-4c8a64e1
18301 Bulk Product 16f9d8c4 Home & Garden $285.98 488 2.1 22 BULK-3ff2343b
18302 Bulk Product 68034a86 Electronics $57.89 347 0.7 85 BULK-97cc9f09
18303 Bulk Product 2ca4a5fb Electronics $227.56 477 1.7 22 BULK-8188de1a
18304 Bulk Product c321cbef Electronics $837.05 113 3.9 84 BULK-3deea1e0
18305 Bulk Product 24df0e57 Sports & Outdoors $24.56 25 1.4 27 BULK-6fd3f138
18306 Bulk Product 118d7d71 Clothing $342.04 279 4.1 86 BULK-330ea4a8
18307 Bulk Product 0740c1b5 Clothing $819.43 110 1.5 78 BULK-96c916ad
18308 Bulk Product f2014996 Clothing $801.65 365 2.3 63 BULK-18f1b3a3
18309 Bulk Product 8de1f29f Books $884.59 181 0.9 45 BULK-bd6a65a7
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