Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

395 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 395 Results Showing 9851 - 9875 of 24441

ID Name Category Price Stock Rating Reviews SKU
10410 Bulk Product f37aeb41 Home & Garden $671.91 217 1.6 1 BULK-a45303a4
10411 Bulk Product 1aa07be1 Books $891.61 207 2.0 90 BULK-a945a5c7
10412 Bulk Product 14dee846 Toys & Games $749.39 216 0.4 5 BULK-92f0b27a
10413 Bulk Product 410c0d54 Toys & Games $1,002.61 366 2.1 35 BULK-bff298ce
10414 Bulk Product f1faf751 Books $24.38 289 3.1 83 BULK-663eb13d
10415 Bulk Product a2ed8520 Sports & Outdoors $272.48 343 4.0 72 BULK-105ccfeb
10416 Bulk Product ee7439e5 Books $474.66 219 2.8 53 BULK-9ad243b0
10417 Bulk Product 8481f77c Home & Garden $427.66 399 0.6 13 BULK-3dd46f57
10418 Bulk Product b0c2f8a5 Sports & Outdoors $237.49 389 4.2 9 BULK-ce30d226
10419 Bulk Product 045b6c26 Sports & Outdoors $496.50 391 3.7 76 BULK-b247f1ad
10420 Bulk Product baf2045f Electronics $457.40 115 4.7 85 BULK-8a4b1dda
10421 Bulk Product 8e103166 Electronics $379.16 380 4.3 5 BULK-f847fb4c
10422 Bulk Product e91a5e3f Books $402.93 382 2.3 80 BULK-7b1b4bf4
10423 Bulk Product 160696ed Sports & Outdoors $727.13 475 3.1 59 BULK-adb0770c
10424 Bulk Product 707a5a50 Electronics $165.61 95 0.9 29 BULK-4a3c7688
10425 Bulk Product 4d2b997c Sports & Outdoors $682.30 297 1.1 24 BULK-7f2eca76
10426 Bulk Product 8937d0f5 Books $299.28 93 4.9 36 BULK-ff4fdcf3
10427 Bulk Product 259f82c9 Home & Garden $691.45 247 0.8 93 BULK-7d3813fd
10428 Bulk Product 9bda6606 Toys & Games $938.64 216 1.0 32 BULK-e1db3db5
10429 Bulk Product 5f6bd276 Clothing $314.63 394 2.4 78 BULK-15307f15
10430 Bulk Product 15ff8ab7 Clothing $329.09 13 4.4 19 BULK-2fcb911e
10431 Bulk Product 0c7b40ec Sports & Outdoors $222.64 34 3.3 55 BULK-d2343060
10432 Bulk Product dd0d8f80 Toys & Games $842.54 430 4.1 45 BULK-4c72b2c3
10433 Bulk Product 1a59791d Electronics $55.90 410 1.2 23 BULK-ab3486cd
10434 Bulk Product 4680d461 Toys & Games $816.62 144 4.1 82 BULK-a53038aa
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