Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

29 ms

Page Size

25

Current Page

717 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 717 Results Showing 17901 - 17925 of 24441

ID Name Category Price Stock Rating Reviews SKU
18460 Bulk Product c8df2cc4 Home & Garden $697.15 404 0.6 44 BULK-334b55eb
18461 Bulk Product 304dd2ed Books $410.75 156 4.1 2 BULK-abd99a1a
18462 Bulk Product e873d20c Electronics $838.59 468 3.3 58 BULK-268a08fa
18463 Bulk Product bda1eb99 Toys & Games $156.71 457 3.4 78 BULK-c5f0e73d
18464 Bulk Product 7941f227 Home & Garden $44.76 195 1.7 11 BULK-3e016165
18465 Bulk Product 7a97c0db Sports & Outdoors $433.64 346 0.9 20 BULK-db3d7d54
18466 Bulk Product 04c60e90 Electronics $85.82 25 4.2 11 BULK-e6c8e70e
18467 Bulk Product f9c0b49e Clothing $639.86 166 1.8 22 BULK-2a15cfd8
18468 Bulk Product 050e7b81 Clothing $438.50 448 0.6 95 BULK-bed4aa65
18469 Bulk Product 4428532b Toys & Games $194.67 435 1.0 57 BULK-86edb67e
18470 Bulk Product 0351a177 Electronics $146.73 269 4.3 88 BULK-08c2bbe7
18471 Bulk Product 40352e3a Electronics $253.89 351 1.8 18 BULK-651c4513
18472 Bulk Product 06501c75 Clothing $306.02 191 3.5 48 BULK-7c46fa48
18473 Bulk Product 72069400 Toys & Games $366.06 136 0.4 54 BULK-1c90a8d2
18474 Bulk Product a657a889 Toys & Games $562.43 351 0.7 36 BULK-f2669de9
18475 Bulk Product 5f965696 Electronics $665.68 171 2.4 10 BULK-5c776609
18476 Bulk Product f85d1ee3 Electronics $229.18 77 4.4 10 BULK-9e10c6db
18477 Bulk Product ebfef0ec Clothing $559.17 310 3.6 17 BULK-38a0e9fc
18478 Bulk Product fcf50d69 Sports & Outdoors $208.80 487 1.4 3 BULK-4f6f3068
18479 Bulk Product 505e983d Sports & Outdoors $780.62 139 3.3 8 BULK-8b81f40c
18480 Bulk Product 1d773b16 Books $809.13 469 1.5 64 BULK-de90963e
18481 Bulk Product 5cf91deb Home & Garden $883.62 333 4.7 40 BULK-d325860f
18482 Bulk Product 73e3ee73 Toys & Games $329.92 267 3.2 70 BULK-fbac3ec3
18483 Bulk Product a572aa3b Electronics $417.49 72 4.6 89 BULK-91a59502
18484 Bulk Product 1f56e776 Books $360.89 349 3.8 4 BULK-3918da9a
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