Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

50

Current Page

316 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 316 Results Showing 15751 - 15800 of 24441

ID Name Category Price Stock Rating Reviews SKU
16310 Bulk Product 27fe72b9 Sports & Outdoors $395.69 290 2.6 51 BULK-1433527c
16311 Bulk Product 4db4240d Sports & Outdoors $747.67 496 0.4 4 BULK-ccf4e2f7
16312 Bulk Product c0ccaedb Sports & Outdoors $104.83 360 4.5 35 BULK-fe82db6f
16313 Bulk Product dff307d7 Home & Garden $665.59 213 0.2 52 BULK-61c7a6e8
16314 Bulk Product 45475fc9 Books $909.42 22 1.9 80 BULK-00531a69
16315 Bulk Product 23e0abd4 Toys & Games $769.84 193 1.2 28 BULK-91a36998
16316 Bulk Product 9ab13638 Clothing $599.56 229 4.1 28 BULK-50f1684e
16317 Bulk Product 856c6d02 Sports & Outdoors $643.98 253 4.4 29 BULK-fff3cd4c
16318 Bulk Product 49f8b68e Sports & Outdoors $593.63 33 1.3 30 BULK-2155af6f
16319 Bulk Product f4771e9d Home & Garden $732.23 402 3.4 17 BULK-3ad953c3
16320 Bulk Product ba65bda5 Books $252.67 355 4.8 38 BULK-92707f5b
16321 Bulk Product 0710d728 Electronics $513.04 363 4.5 41 BULK-a61c31b1
16322 Bulk Product 14f1130d Electronics $145.10 75 1.6 30 BULK-56c116f6
16323 Bulk Product 5be279bb Home & Garden $126.17 415 2.1 81 BULK-3581d30a
16324 Bulk Product 3bfc5705 Toys & Games $621.43 230 1.5 28 BULK-8c6248b5
16325 Bulk Product 866ee153 Books $686.48 239 0.8 56 BULK-43d7e3e9
16326 Bulk Product 76ceeac5 Toys & Games $453.45 378 0.2 43 BULK-53dbd250
16327 Bulk Product 3114f2f9 Sports & Outdoors $137.12 246 4.4 61 BULK-9130d270
16328 Bulk Product f668a768 Home & Garden $737.34 145 1.4 44 BULK-ae787fa4
16329 Bulk Product 170cce07 Toys & Games $777.81 118 4.4 64 BULK-b53a3251
16330 Bulk Product 68c1d39d Home & Garden $610.41 152 1.8 90 BULK-d7bf29f2
16331 Bulk Product 7f2db429 Clothing $102.05 459 3.3 85 BULK-04eb11b0
16332 Bulk Product e6a1718d Home & Garden $606.66 437 2.3 92 BULK-637964e3
16333 Bulk Product 05feee58 Home & Garden $552.99 23 2.3 27 BULK-e85d6fe2
16334 Bulk Product bc3a3260 Sports & Outdoors $18.48 427 4.6 88 BULK-41d3309d
16335 Bulk Product 71353155 Books $245.41 453 4.6 23 BULK-eaf88ad7
16336 Bulk Product 097f46a5 Electronics $904.65 413 1.1 35 BULK-22eedd96
16337 Bulk Product a0167f8b Books $866.05 281 4.5 7 BULK-8522ed01
16338 Bulk Product 4f0c5a4c Home & Garden $648.46 154 3.3 27 BULK-92ad219c
16339 Bulk Product ca5d467a Clothing $442.96 353 2.5 16 BULK-70d4b581
16340 Bulk Product 865c40c2 Sports & Outdoors $385.42 454 2.1 47 BULK-f89ef0a7
16341 Bulk Product 277e089d Books $728.59 202 3.7 60 BULK-55972a06
16342 Bulk Product 1adbbae5 Sports & Outdoors $772.42 437 2.0 22 BULK-4963f1cd
16343 Bulk Product c4188c81 Sports & Outdoors $812.59 322 2.7 47 BULK-668393a6
16344 Bulk Product 33eefd3d Sports & Outdoors $993.79 108 1.6 19 BULK-d1b2aa73
16345 Bulk Product d25d7f15 Home & Garden $245.19 10 1.5 18 BULK-f0254538
16346 Bulk Product a1c4d007 Books $432.23 432 2.4 11 BULK-d6724feb
16347 Bulk Product 4842b136 Clothing $990.09 92 0.7 9 BULK-41567412
16348 Bulk Product 48e287aa Sports & Outdoors $930.90 30 4.2 38 BULK-0c00ce0c
16349 Bulk Product d9a9d5a0 Electronics $260.51 361 2.4 94 BULK-cd3c79b6
16350 Bulk Product 74ad12f9 Electronics $26.95 1 3.1 65 BULK-11637bc7
16351 Bulk Product 45427eea Clothing $252.04 440 1.4 46 BULK-ff020073
16352 Bulk Product 9075a438 Toys & Games $439.39 310 4.8 12 BULK-0c63de25
16353 Bulk Product 040de253 Books $263.15 254 3.7 66 BULK-0097529b
16354 Bulk Product 402fe13a Toys & Games $665.71 379 0.1 43 BULK-ab3b00d9
16355 Bulk Product 4cb87bb0 Sports & Outdoors $577.24 89 1.8 48 BULK-e7bc89a9
16356 Bulk Product a13330e8 Home & Garden $500.27 47 2.9 58 BULK-909cd268
16357 Bulk Product 265a5a6d Books $381.74 197 1.5 73 BULK-52dea818
16358 Bulk Product 097baa6b Toys & Games $960.92 487 3.0 15 BULK-1c223829
16359 Bulk Product ebff6d92 Home & Garden $391.18 267 3.7 70 BULK-1e84e346
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