Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

477 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 477 Results Showing 11901 - 11925 of 24441

ID Name Category Price Stock Rating Reviews SKU
12460 Bulk Product ac819610 Electronics $664.76 133 2.8 71 BULK-4af1de86
12461 Bulk Product da4c81a9 Clothing $406.08 385 4.7 81 BULK-9c078c3b
12462 Bulk Product 173db9cd Home & Garden $230.07 107 3.0 60 BULK-5c7ff23e
12463 Bulk Product c2fc34f3 Clothing $139.45 186 2.2 91 BULK-7b67963b
12464 Bulk Product a342a029 Books $172.23 103 1.3 1 BULK-262ef2cb
12465 Bulk Product c015806a Clothing $558.01 445 3.3 92 BULK-041e81ac
12466 Bulk Product 79da9ce4 Clothing $802.67 271 3.9 39 BULK-5a4fa728
12467 Bulk Product b528b944 Clothing $539.98 254 2.5 3 BULK-371db358
12468 Bulk Product 498ff0c1 Clothing $615.88 25 0.6 44 BULK-ac8ab8f4
12469 Bulk Product 696c14ae Sports & Outdoors $861.00 302 2.2 8 BULK-f8ca40b7
12470 Bulk Product afc87bb8 Sports & Outdoors $593.16 350 2.4 67 BULK-c66100a0
12471 Bulk Product 651f5c88 Clothing $243.29 354 2.9 44 BULK-fd5932d7
12472 Bulk Product d42a530e Sports & Outdoors $869.50 197 3.1 9 BULK-3ad52581
12473 Bulk Product 59d28d64 Electronics $519.70 159 2.1 59 BULK-766daea4
12474 Bulk Product aca45491 Toys & Games $555.86 136 1.9 63 BULK-7a6ecaeb
12475 Bulk Product 9fecec55 Clothing $215.37 151 2.4 97 BULK-a54658ed
12476 Bulk Product 6cddb3e0 Clothing $419.94 305 2.9 58 BULK-116c63da
12477 Bulk Product d0baa85b Toys & Games $155.53 225 1.3 25 BULK-dedeb10e
12478 Bulk Product 46e186b6 Clothing $908.07 463 2.9 65 BULK-d2e7aac8
12479 Bulk Product c08ac4d5 Clothing $366.23 74 4.6 41 BULK-f0e2c438
12480 Bulk Product ebfebb70 Home & Garden $481.28 383 3.8 1 BULK-e882d4ba
12481 Bulk Product c42784ea Home & Garden $713.70 493 2.5 91 BULK-93e97432
12482 Bulk Product ecfaa8a6 Toys & Games $866.67 364 0.6 67 BULK-84929863
12483 Bulk Product 9e9477c5 Books $550.01 330 3.6 79 BULK-9dbef7cd
12484 Bulk Product 40d03ea4 Sports & Outdoors $267.78 297 3.0 60 BULK-a4a18592
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