Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

44 ms

Page Size

25

Current Page

266 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 266 Results Showing 6626 - 6650 of 24441

ID Name Category Price Stock Rating Reviews SKU
7185 Bulk Product f1b946e2 Toys & Games $998.14 200 3.8 61 BULK-1bbbcb4d
7186 Bulk Product c906edbd Sports & Outdoors $485.11 184 3.0 5 BULK-9e920270
7187 Bulk Product 083e1588 Books $160.82 344 2.1 44 BULK-f92c5cec
7188 Bulk Product b2094200 Clothing $927.63 299 2.0 14 BULK-a027c9d8
7189 Bulk Product 89c6396d Home & Garden $505.24 253 0.1 73 BULK-81677de0
7190 Bulk Product 1bc940ec Toys & Games $130.35 340 1.8 25 BULK-2b0cc9a1
7191 Bulk Product 12ec7af9 Electronics $996.16 91 2.6 27 BULK-85b67921
7192 Bulk Product 6123d603 Home & Garden $231.34 15 1.9 99 BULK-8cd6dd22
7193 Bulk Product 41b9f627 Electronics $502.49 0 4.1 59 BULK-74ae258b
7194 Bulk Product 9c2776c8 Books $507.74 152 2.6 81 BULK-7cda2cb2
7195 Bulk Product a85ec2aa Home & Garden $470.29 483 3.2 3 BULK-cb951e20
7196 Bulk Product a5442ece Sports & Outdoors $877.34 116 0.8 11 BULK-00a2b874
7197 Bulk Product 4c224796 Electronics $17.89 347 0.6 98 BULK-11e5a323
7198 Bulk Product 8885ed5e Toys & Games $373.28 212 4.1 63 BULK-761c25e9
7199 Bulk Product aa9f99f6 Electronics $839.17 109 4.6 4 BULK-49fd1a95
7200 Bulk Product c89c927a Toys & Games $266.48 46 2.0 40 BULK-a59a3e78
7201 Bulk Product ca488c2a Clothing $393.33 80 4.1 39 BULK-1d5e4389
7202 Bulk Product e09c8e97 Clothing $237.15 364 0.6 21 BULK-a35eacd6
7203 Bulk Product 59d1102d Sports & Outdoors $839.18 195 2.4 89 BULK-6dbef5aa
7204 Bulk Product ce866757 Home & Garden $390.04 296 4.7 30 BULK-1d86d149
7205 Bulk Product 1cd85988 Home & Garden $161.61 358 0.6 57 BULK-d1294cb2
7206 Bulk Product f85eef5d Electronics $380.83 70 4.3 14 BULK-e429fca2
7207 Bulk Product bf37684f Clothing $720.40 92 0.5 2 BULK-c7467442
7208 Bulk Product ae125623 Home & Garden $571.47 94 4.9 43 BULK-e0fd2526
7209 Bulk Product 883d582b Electronics $881.09 39 0.8 36 BULK-e2e7eb86
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