Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

704 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 704 Results Showing 17576 - 17600 of 24441

ID Name Category Price Stock Rating Reviews SKU
18135 Bulk Product 021c572b Home & Garden $728.89 12 2.3 0 BULK-4eceb4ba
18136 Bulk Product f986e501 Sports & Outdoors $689.11 462 0.4 41 BULK-50a6eeae
18137 Bulk Product 2466f262 Electronics $313.77 305 4.7 6 BULK-d419c984
18138 Bulk Product 596de547 Books $659.18 193 0.8 67 BULK-8883374d
18139 Bulk Product 38c647bc Electronics $15.66 296 1.9 41 BULK-cbc92f56
18140 Bulk Product 90e12cb1 Books $963.77 216 4.1 4 BULK-d4732d14
18141 Bulk Product 2d48ce33 Home & Garden $53.25 469 0.6 7 BULK-2f30d006
18142 Bulk Product 2a414676 Sports & Outdoors $773.08 57 3.5 93 BULK-78080d1d
18143 Bulk Product 8aa34809 Electronics $247.07 375 3.6 37 BULK-f6ed7475
18144 Bulk Product 6bb76ebf Clothing $228.40 202 1.9 8 BULK-9445807e
18145 Bulk Product b1292e99 Electronics $550.69 324 4.3 56 BULK-319735cb
18146 Bulk Product 72cc42d5 Sports & Outdoors $283.39 115 4.5 45 BULK-90e51ecb
18147 Bulk Product b27ed9d3 Toys & Games $209.89 358 3.5 63 BULK-b979a1c4
18148 Bulk Product af9c3168 Home & Garden $95.45 276 4.5 24 BULK-880af438
18149 Bulk Product 86d2f570 Home & Garden $424.27 482 4.6 28 BULK-278eccf8
18150 Bulk Product 92e74ca8 Clothing $556.17 24 5.0 73 BULK-0a126e47
18151 Bulk Product 3d79da44 Sports & Outdoors $601.18 267 3.8 64 BULK-557d2a86
18152 Bulk Product 3236a27c Toys & Games $988.55 398 4.9 7 BULK-5671b0c3
18153 Bulk Product 9fb847dc Clothing $411.65 467 3.8 83 BULK-735dcdad
18154 Bulk Product 75fc1081 Home & Garden $458.43 259 4.5 24 BULK-e4e9dc91
18155 Bulk Product 499d2c4c Clothing $193.51 112 2.5 99 BULK-e306cd5c
18156 Bulk Product 7c1278d8 Clothing $408.59 398 1.4 69 BULK-324db712
18157 Bulk Product a8937bc6 Books $939.75 126 2.2 98 BULK-ae099b2d
18158 Bulk Product a15e962c Electronics $463.03 373 0.5 44 BULK-bc33d707
18159 Bulk Product e8429e67 Home & Garden $451.53 269 4.0 73 BULK-c8353c40
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