Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

508 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 508 Results Showing 12676 - 12700 of 24441

ID Name Category Price Stock Rating Reviews SKU
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