Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

404 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 404 Results Showing 10076 - 10100 of 24441

ID Name Category Price Stock Rating Reviews SKU
10635 Bulk Product 34b087b2 Clothing $136.45 484 2.4 91 BULK-fc0800dc
10636 Bulk Product 7366e9ab Books $538.93 480 3.1 33 BULK-d880697b
10637 Bulk Product 8d8f9bfb Toys & Games $519.83 77 1.4 98 BULK-8709bdfb
10638 Bulk Product fb80cc0d Clothing $210.41 284 4.8 60 BULK-8d135d6f
10639 Bulk Product 37f058b0 Clothing $756.70 301 1.4 18 BULK-d2aa222d
10640 Bulk Product 48d55487 Clothing $786.00 90 3.6 90 BULK-328735d1
10641 Bulk Product c631069c Books $614.08 389 4.0 98 BULK-012113ce
10642 Bulk Product f087ad07 Books $118.13 160 1.6 63 BULK-fe5b78db
10643 Bulk Product bdcf7ea3 Home & Garden $707.34 302 2.9 22 BULK-f26d5184
10644 Bulk Product c21b249a Clothing $855.03 246 1.8 19 BULK-58ac381d
10645 Bulk Product 7d8c745f Sports & Outdoors $448.16 354 4.9 1 BULK-83557be2
10646 Bulk Product 28152fba Books $33.78 233 4.6 81 BULK-b0ec2630
10647 Bulk Product 72d7d36a Electronics $440.02 205 1.1 75 BULK-5a7099a1
10648 Bulk Product 4c510e0f Clothing $885.57 491 2.3 52 BULK-2a2ac818
10649 Bulk Product df786e98 Books $258.04 386 2.9 29 BULK-a5da854e
10650 Bulk Product 3376d79e Toys & Games $446.64 248 3.2 8 BULK-40f8179b
10651 Bulk Product 030e451f Clothing $212.54 440 3.1 24 BULK-facb0297
10652 Bulk Product 41bb7624 Sports & Outdoors $559.65 68 4.2 98 BULK-8e0788e2
10653 Bulk Product 74831527 Toys & Games $982.15 385 0.9 69 BULK-2efcf449
10654 Bulk Product 9c1ccde2 Books $73.49 378 3.1 6 BULK-9d4e3749
10655 Bulk Product 76e63a51 Sports & Outdoors $477.54 455 4.3 76 BULK-774771f3
10656 Bulk Product eecb1311 Electronics $277.58 155 2.9 30 BULK-f03eb57b
10657 Bulk Product e872dbad Electronics $686.72 425 3.7 58 BULK-7c6bdac7
10658 Bulk Product 1ae08757 Books $297.05 28 4.5 61 BULK-e6c81aaa
10659 Bulk Product ef445373 Electronics $710.99 312 2.7 89 BULK-1131bc6e
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