Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

959 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 959 Results Showing 23951 - 23975 of 24441

ID Name Category Price Stock Rating Reviews SKU
24510 Bulk Product 2ee663fc Sports & Outdoors $29.88 361 1.9 54 BULK-bed1e643
24511 Bulk Product 900bcefe Clothing $641.13 322 1.7 35 BULK-29429a3c
24512 Bulk Product d551888c Books $536.57 13 2.2 22 BULK-863862e5
24513 Bulk Product c98bfa6f Books $105.29 77 4.9 7 BULK-03880dfa
24514 Bulk Product d6f00030 Clothing $198.08 284 0.1 7 BULK-1d2e131f
24515 Bulk Product 3b931a14 Clothing $464.65 411 2.9 91 BULK-90960cab
24516 Bulk Product 02a2710b Toys & Games $50.41 52 1.1 32 BULK-7f0e5c1a
24517 Bulk Product a2412c8d Clothing $791.45 334 0.9 75 BULK-099ea747
24518 Bulk Product c753ce42 Electronics $897.37 325 1.9 84 BULK-7bbd363f
24519 Bulk Product 7a72cd49 Toys & Games $946.07 332 0.8 40 BULK-5cc30e87
24520 Bulk Product 54c24487 Books $530.96 219 0.5 89 BULK-5fb83355
24521 Bulk Product 85eb6bab Sports & Outdoors $378.65 238 2.3 42 BULK-7e472218
24522 Bulk Product d6f0d31f Electronics $27.18 27 0.7 24 BULK-97f90cf1
24523 Bulk Product 20424969 Toys & Games $766.90 49 4.1 22 BULK-40cda2c9
24524 Bulk Product 906a1cd9 Home & Garden $598.36 366 1.4 20 BULK-b11cb44a
24525 Bulk Product 48f00d2a Clothing $456.68 419 2.7 70 BULK-131be105
24526 Bulk Product f7437518 Home & Garden $442.46 17 1.8 49 BULK-0d17a0f8
24527 Bulk Product 0cbb4ff7 Clothing $228.91 29 2.2 78 BULK-ecd8e09b
24528 Bulk Product 99d8763a Books $941.41 29 4.2 4 BULK-716042d2
24529 Bulk Product 0eb305ca Toys & Games $345.53 338 2.1 94 BULK-cb2b96fe
24530 Bulk Product a94d85f8 Books $534.28 416 2.5 37 BULK-041534dd
24531 Bulk Product 188053d6 Home & Garden $695.81 329 1.1 32 BULK-4cb6331a
24532 Bulk Product 31cc3797 Sports & Outdoors $526.07 125 1.5 17 BULK-8acd6f41
24533 Bulk Product f3e780e1 Toys & Games $947.37 290 4.1 1 BULK-e668ee4b
24534 Bulk Product 3b878a3c Sports & Outdoors $860.69 78 1.5 35 BULK-48540615
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