Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

434 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 434 Results Showing 10826 - 10850 of 24441

ID Name Category Price Stock Rating Reviews SKU
11385 Bulk Product ce185152 Electronics $920.23 94 2.3 2 BULK-c9013676
11386 Bulk Product 0613ad46 Clothing $885.59 336 0.5 70 BULK-6823422e
11387 Bulk Product 5aba0703 Toys & Games $555.18 180 0.6 11 BULK-455de0f8
11388 Bulk Product d8817673 Books $353.14 367 0.4 59 BULK-5cacb792
11389 Bulk Product 30da4b12 Home & Garden $25.25 354 0.7 49 BULK-f5d6bafd
11390 Bulk Product e7496266 Clothing $826.10 153 4.6 89 BULK-8cda7e1a
11391 Bulk Product 7af8553d Toys & Games $502.81 418 4.0 92 BULK-1d372053
11392 Bulk Product 5edf3495 Sports & Outdoors $563.63 377 4.5 45 BULK-a55e522f
11393 Bulk Product 5d5c5481 Clothing $561.32 0 0.1 42 BULK-25a1673d
11394 Bulk Product 5c5640b0 Home & Garden $988.10 82 5.0 79 BULK-48d2acf1
11395 Bulk Product 93a4cd14 Electronics $389.64 390 3.4 71 BULK-71e5592d
11396 Bulk Product 885b7047 Toys & Games $95.14 433 4.2 83 BULK-435bcd98
11397 Bulk Product 6377559c Sports & Outdoors $596.95 147 2.0 47 BULK-c8f423fa
11398 Bulk Product 6932ed96 Electronics $60.82 428 4.3 79 BULK-9b3567bf
11399 Bulk Product b6b7f328 Toys & Games $286.92 214 0.4 12 BULK-956a998c
11400 Bulk Product 2002034c Sports & Outdoors $349.88 181 2.9 65 BULK-4eb0554e
11401 Bulk Product 41472b83 Toys & Games $270.65 48 2.0 48 BULK-44f30264
11402 Bulk Product b219879d Toys & Games $38.81 165 2.3 68 BULK-b3549728
11403 Bulk Product 9b7d1f1b Clothing $385.54 222 4.2 93 BULK-090b8a56
11404 Bulk Product 84f035a5 Home & Garden $943.78 356 0.3 22 BULK-9f2ba502
11405 Bulk Product 074e6506 Clothing $862.85 210 3.1 6 BULK-4fb72877
11406 Bulk Product d7686f29 Toys & Games $625.63 324 2.5 99 BULK-d7333f8b
11407 Bulk Product 01e7ce90 Books $188.14 440 4.0 95 BULK-fbb69154
11408 Bulk Product c610141b Clothing $155.46 393 3.0 33 BULK-1971351c
11409 Bulk Product 804f2eac Sports & Outdoors $886.77 91 3.1 13 BULK-2dfbe3c4
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