Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

771 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 771 Results Showing 19251 - 19275 of 24441

ID Name Category Price Stock Rating Reviews SKU
19810 Bulk Product d977279d Toys & Games $15.58 333 2.8 63 BULK-aee13fd1
19811 Bulk Product baa1c570 Clothing $10.94 11 0.3 47 BULK-f50adb2e
19812 Bulk Product 19f78085 Clothing $987.71 273 0.8 32 BULK-8eaee4db
19813 Bulk Product 840ca83b Home & Garden $281.44 211 1.8 99 BULK-9c1c896a
19814 Bulk Product 6b59a64c Electronics $494.66 27 2.8 89 BULK-c9bc0d1c
19815 Bulk Product d77f47b0 Clothing $406.18 357 1.4 43 BULK-63624574
19816 Bulk Product a0e87d7c Books $191.92 318 1.5 31 BULK-3da35b3b
19817 Bulk Product 956a63f3 Home & Garden $424.57 86 0.5 32 BULK-623002bb
19818 Bulk Product ad2b33bd Clothing $935.53 415 4.5 97 BULK-4ad005b5
19819 Bulk Product c30d6adf Toys & Games $301.54 455 4.7 36 BULK-a01378de
19820 Bulk Product b5e77f58 Home & Garden $510.44 101 4.2 50 BULK-7f7887c5
19821 Bulk Product 9d097f1a Electronics $488.97 443 3.3 1 BULK-5af25c2b
19822 Bulk Product 14d6a2a3 Toys & Games $708.46 360 2.3 7 BULK-3528eb26
19823 Bulk Product 14af7dc4 Home & Garden $527.22 499 2.4 16 BULK-d0acd1e4
19824 Bulk Product 27462006 Books $326.81 387 4.9 34 BULK-bfa920a9
19825 Bulk Product a9d96c80 Clothing $660.08 37 0.9 73 BULK-b4d804f3
19826 Bulk Product 664b3a21 Clothing $428.59 458 4.9 0 BULK-90776048
19827 Bulk Product 7729b2fe Home & Garden $833.46 456 4.1 8 BULK-6be61576
19828 Bulk Product b5ab8869 Home & Garden $801.21 101 2.2 41 BULK-8a2c1a38
19829 Bulk Product 6232f3b8 Home & Garden $970.57 118 3.5 47 BULK-eb44ca29
19830 Bulk Product d90ec00c Clothing $929.00 1 2.0 74 BULK-d434a029
19831 Bulk Product a651b7c6 Sports & Outdoors $209.51 136 1.7 79 BULK-4ba167d4
19832 Bulk Product 8da1be87 Clothing $315.08 420 2.2 90 BULK-2fdd8815
19833 Bulk Product cc3f2470 Books $532.40 494 3.1 35 BULK-06a79f6e
19834 Bulk Product 73a9b617 Clothing $698.90 446 0.7 2 BULK-ed5d9993
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