Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

546 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 546 Results Showing 13626 - 13650 of 24441

ID Name Category Price Stock Rating Reviews SKU
14185 Bulk Product 48469eb8 Sports & Outdoors $538.12 168 4.6 1 BULK-4e632561
14186 Bulk Product 3a6fa98c Clothing $338.36 185 3.3 47 BULK-c0625bdf
14187 Bulk Product b418c0b4 Electronics $77.43 202 4.7 5 BULK-538f4d86
14188 Bulk Product bda1819f Electronics $173.73 146 1.6 53 BULK-bc4158d9
14189 Bulk Product aa1ed218 Home & Garden $509.21 245 0.4 20 BULK-6a73469e
14190 Bulk Product 8104dc25 Clothing $879.51 298 2.9 99 BULK-f40f4a8e
14191 Bulk Product b62bef11 Books $977.82 282 1.0 87 BULK-2258fd87
14192 Bulk Product 216741ef Toys & Games $293.22 450 3.5 57 BULK-f7b502a3
14193 Bulk Product dbb5cfc4 Home & Garden $760.99 31 4.4 17 BULK-718e3841
14194 Bulk Product 090780d7 Toys & Games $814.68 382 1.4 81 BULK-ac8177cf
14195 Bulk Product d039379a Books $176.04 34 2.4 45 BULK-7649ff0a
14196 Bulk Product 1ac7c87a Electronics $41.54 12 3.5 57 BULK-c0d21f93
14197 Bulk Product a9361940 Books $104.82 277 1.3 85 BULK-66b9695c
14198 Bulk Product e506e2d4 Toys & Games $853.55 61 4.7 83 BULK-b15fea98
14199 Bulk Product 33f864d4 Books $143.30 122 3.1 67 BULK-188eb5a2
14200 Bulk Product 4c0abeb8 Electronics $98.00 128 5.0 22 BULK-26840ffc
14201 Bulk Product 364def1d Sports & Outdoors $359.26 125 3.7 28 BULK-15a96a87
14202 Bulk Product b5a82478 Electronics $253.56 489 3.5 48 BULK-3ea81645
14203 Bulk Product 086ca0dd Books $769.80 7 4.2 42 BULK-7c36171c
14204 Bulk Product fced2f7b Books $353.13 19 0.7 62 BULK-f5a08a18
14205 Bulk Product b7bef8cd Toys & Games $297.51 65 4.6 66 BULK-a4780f78
14206 Bulk Product 108ede83 Books $443.83 492 2.8 92 BULK-9df800e8
14207 Bulk Product 7f3a9525 Home & Garden $326.86 420 0.0 83 BULK-b9499eb8
14208 Bulk Product 827c4ded Sports & Outdoors $331.30 65 0.1 96 BULK-842029e5
14209 Bulk Product f8a4df47 Home & Garden $806.97 485 4.3 96 BULK-2ee8866e
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