Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

597 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 597 Results Showing 14901 - 14925 of 24441

ID Name Category Price Stock Rating Reviews SKU
15460 Bulk Product 2054d12d Sports & Outdoors $697.32 467 4.6 7 BULK-95875094
15461 Bulk Product 46c72da9 Clothing $890.19 221 3.5 41 BULK-45f77004
15462 Bulk Product 7f45cbf6 Electronics $200.69 314 1.1 92 BULK-a18fd470
15463 Bulk Product 83ebdd1f Electronics $740.15 100 1.2 75 BULK-d5d75a3b
15464 Bulk Product 5acdcdee Clothing $325.58 181 4.3 97 BULK-fa458dff
15465 Bulk Product 4c6ee5af Books $776.18 313 4.4 56 BULK-8f09d2a2
15466 Bulk Product f0f868b6 Electronics $432.49 477 3.5 55 BULK-290b99c4
15467 Bulk Product 848a0ab8 Sports & Outdoors $578.38 145 1.3 75 BULK-0628bbcc
15468 Bulk Product ae338767 Electronics $498.18 140 0.7 20 BULK-7e869da2
15469 Bulk Product ddcb6717 Toys & Games $455.38 143 2.1 16 BULK-f84e9865
15470 Bulk Product 4cdfb0d4 Electronics $320.42 66 1.7 90 BULK-bb14deab
15471 Bulk Product 2e2b0849 Clothing $746.56 39 4.9 45 BULK-f9e0d5ce
15472 Bulk Product b82f32cf Toys & Games $929.69 490 1.1 8 BULK-ca14f056
15473 Bulk Product cb18dacd Clothing $590.42 160 5.0 61 BULK-3e53d12a
15474 Bulk Product b7667186 Clothing $673.69 254 1.5 99 BULK-19090e02
15475 Bulk Product 84f2bfb1 Toys & Games $140.85 324 2.5 5 BULK-8c25c044
15476 Bulk Product 9d601469 Home & Garden $270.47 271 0.6 1 BULK-bd1737f8
15477 Bulk Product 55f936a1 Clothing $467.38 81 1.7 66 BULK-e84790f9
15478 Bulk Product 8bdd988e Toys & Games $923.15 21 0.7 80 BULK-7cded128
15479 Bulk Product 8aa6b520 Clothing $161.33 209 2.6 58 BULK-f6d52656
15480 Bulk Product 76a2c2d2 Sports & Outdoors $71.87 279 0.4 96 BULK-cf0e52c2
15481 Bulk Product fafa4662 Books $104.74 434 1.9 47 BULK-9636add1
15482 Bulk Product a1dba939 Home & Garden $525.64 90 3.0 34 BULK-e7d47b59
15483 Bulk Product 0c7c89de Electronics $811.41 431 1.5 11 BULK-3b206cd5
15484 Bulk Product 010a1fe8 Books $102.87 335 2.5 97 BULK-bcc75716
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