Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

50

Current Page

254 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 254 Results Showing 12651 - 12700 of 24441

ID Name Category Price Stock Rating Reviews SKU
13210 Bulk Product e8cec06e Electronics $141.10 2 4.4 75 BULK-2f8d4013
13211 Bulk Product 7e67694d Clothing $125.18 360 2.8 18 BULK-0fff3438
13212 Bulk Product dbdd78d1 Toys & Games $637.25 415 5.0 61 BULK-66f11ce1
13213 Bulk Product 1a8e26ef Toys & Games $539.45 198 3.1 48 BULK-b3a56683
13214 Bulk Product 5d5ed162 Sports & Outdoors $35.62 132 0.9 47 BULK-6526602a
13215 Bulk Product 74d4908c Sports & Outdoors $30.97 115 4.2 88 BULK-0d1e0a58
13216 Bulk Product 8eb4d99a Books $479.35 92 0.2 9 BULK-383dfadc
13217 Bulk Product 80e791f5 Sports & Outdoors $34.02 258 3.0 19 BULK-b6e08e4d
13218 Bulk Product 6e2a51f6 Clothing $94.63 98 2.3 64 BULK-a7caf0e7
13219 Bulk Product ceed17a5 Books $64.09 98 0.4 51 BULK-197e7500
13220 Bulk Product 5e104f69 Sports & Outdoors $561.16 210 3.3 51 BULK-f076910f
13221 Bulk Product c0533a5f Electronics $664.19 402 2.5 19 BULK-226fe1f0
13222 Bulk Product d518a599 Toys & Games $142.08 141 2.4 81 BULK-938420a5
13223 Bulk Product 80d6bfe8 Books $846.50 136 4.9 16 BULK-1c4144fa
13224 Bulk Product c43ea6d8 Home & Garden $933.39 401 0.3 14 BULK-7fbaaf49
13225 Bulk Product 7fbdf94f Toys & Games $253.11 477 1.1 26 BULK-4365f6de
13226 Bulk Product a76708cd Books $86.50 487 3.3 98 BULK-5cae23b9
13227 Bulk Product 70553050 Toys & Games $146.56 53 2.3 96 BULK-e639822f
13228 Bulk Product 7b64897b Electronics $220.28 480 1.7 14 BULK-877a50ca
13229 Bulk Product 2208a63f Sports & Outdoors $955.54 15 0.6 40 BULK-4b8a93d9
13230 Bulk Product 2a284e30 Books $549.43 8 2.9 58 BULK-ec68d467
13231 Bulk Product bdd2dacf Books $337.16 198 1.5 46 BULK-2ce4f7ee
13232 Bulk Product 562a3151 Home & Garden $521.22 240 0.4 73 BULK-5513b4e3
13233 Bulk Product b1c8dc81 Clothing $756.77 89 0.9 67 BULK-d2271fea
13234 Bulk Product 9eacdfb9 Sports & Outdoors $530.62 39 2.4 92 BULK-89d272a1
13235 Bulk Product 8eaf0818 Books $758.79 194 3.0 96 BULK-d5e4075a
13236 Bulk Product 01339366 Sports & Outdoors $366.44 112 2.2 4 BULK-da8bc780
13237 Bulk Product b66d75c2 Electronics $895.72 228 3.3 10 BULK-33f5ed4d
13238 Bulk Product 3af858d4 Sports & Outdoors $813.26 416 0.6 33 BULK-8f0942f9
13239 Bulk Product 9372c1f7 Sports & Outdoors $566.01 176 3.3 72 BULK-f6bd3eca
13240 Bulk Product f3f57926 Electronics $332.30 312 3.4 22 BULK-04d7dc93
13241 Bulk Product 069f1ef2 Sports & Outdoors $132.31 224 1.3 90 BULK-0d28c04d
13242 Bulk Product 0c491b58 Electronics $418.49 188 3.7 46 BULK-7cddd236
13243 Bulk Product 5f3a630f Electronics $845.59 353 3.3 85 BULK-89d9f909
13244 Bulk Product a5f6a2df Home & Garden $682.06 164 3.4 43 BULK-cf6b4f4a
13245 Bulk Product 16f8c468 Sports & Outdoors $495.07 316 4.8 90 BULK-a8ab293b
13246 Bulk Product 8ba91bcb Home & Garden $504.04 238 4.8 89 BULK-c506a2e2
13247 Bulk Product c20baec9 Books $159.58 261 1.3 3 BULK-f5167295
13248 Bulk Product 6f23aedd Toys & Games $947.18 317 1.6 77 BULK-3cd1bb79
13249 Bulk Product 738b808a Sports & Outdoors $748.34 327 0.5 67 BULK-7cc5f43e
13250 Bulk Product 121267f8 Books $812.20 493 4.0 28 BULK-3bef34cd
13251 Bulk Product ca7b88b0 Books $134.28 434 2.9 29 BULK-9488709a
13252 Bulk Product 33d3b9a7 Home & Garden $349.18 298 3.6 9 BULK-64806138
13253 Bulk Product 29bdaf83 Toys & Games $141.86 58 2.5 73 BULK-500413fe
13254 Bulk Product 1a372d15 Toys & Games $865.86 392 2.5 61 BULK-477deec6
13255 Bulk Product b85385a1 Home & Garden $134.36 282 1.5 27 BULK-bd0b2b8a
13256 Bulk Product 9746c82c Clothing $820.45 44 1.1 84 BULK-c8ffa34d
13257 Bulk Product ad5b5492 Clothing $720.72 430 2.8 33 BULK-748c2e2b
13258 Bulk Product 1119cda3 Toys & Games $144.15 414 4.6 90 BULK-8c9d84dc
13259 Bulk Product b3ed78dd Electronics $44.15 111 1.4 86 BULK-1b14548a
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