Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

747 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 747 Results Showing 18651 - 18675 of 24441

ID Name Category Price Stock Rating Reviews SKU
19210 Bulk Product f1d10253 Home & Garden $824.62 35 0.0 87 BULK-f7c6ef6e
19211 Bulk Product bbf28c06 Sports & Outdoors $718.98 375 4.2 89 BULK-44ff1bb2
19212 Bulk Product 8723151d Books $512.48 27 0.6 77 BULK-7bbbe9c9
19213 Bulk Product e3104ff2 Books $584.67 320 4.1 80 BULK-22c86b3b
19214 Bulk Product f1f7a11d Home & Garden $34.90 210 4.3 21 BULK-c48a388f
19215 Bulk Product 125c025f Home & Garden $887.00 465 4.2 90 BULK-5aeef953
19216 Bulk Product 91c93043 Books $147.44 343 2.4 44 BULK-c5c62840
19217 Bulk Product 6f1ebbf0 Sports & Outdoors $549.91 272 1.6 69 BULK-f660e173
19218 Bulk Product 7125c00c Sports & Outdoors $376.46 41 3.0 3 BULK-0eb7af72
19219 Bulk Product 985b5466 Books $888.74 37 4.4 34 BULK-ef036d7e
19220 Bulk Product 5dc40885 Home & Garden $207.15 386 1.2 81 BULK-84c8fd43
19221 Bulk Product 2790fb30 Toys & Games $983.31 152 2.2 6 BULK-3c392630
19222 Bulk Product f2f77aeb Electronics $601.39 285 0.7 22 BULK-44ed5709
19223 Bulk Product 674c8838 Books $22.30 250 2.1 99 BULK-910076f5
19224 Bulk Product 19a329db Toys & Games $310.89 231 3.6 60 BULK-29256ebc
19225 Bulk Product fd4a6d39 Toys & Games $565.93 210 2.9 34 BULK-dc721a92
19226 Bulk Product 337b4db9 Home & Garden $911.20 74 0.6 30 BULK-1f15de4c
19227 Bulk Product dbea0343 Clothing $1,006.89 73 3.6 28 BULK-742ffaef
19228 Bulk Product 1b6a1d63 Home & Garden $454.28 356 3.1 38 BULK-a9b5bbfd
19229 Bulk Product 44346995 Home & Garden $931.87 218 2.9 15 BULK-c5e75502
19230 Bulk Product acad4f32 Electronics $761.09 241 4.9 20 BULK-7d4a0f84
19231 Bulk Product 7615ac85 Home & Garden $643.86 376 3.3 33 BULK-fa605a6e
19232 Bulk Product cd769df9 Sports & Outdoors $24.73 489 4.7 64 BULK-7c02ecac
19233 Bulk Product 22b79403 Clothing $276.20 163 1.7 45 BULK-4229b6d0
19234 Bulk Product 35765ebe Clothing $834.41 355 2.2 41 BULK-3489d6e6
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