Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

631 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 631 Results Showing 15751 - 15775 of 24441

ID Name Category Price Stock Rating Reviews SKU
16310 Bulk Product 27fe72b9 Sports & Outdoors $395.69 290 2.6 51 BULK-1433527c
16311 Bulk Product 4db4240d Sports & Outdoors $747.67 496 0.4 4 BULK-ccf4e2f7
16312 Bulk Product c0ccaedb Sports & Outdoors $104.83 360 4.5 35 BULK-fe82db6f
16313 Bulk Product dff307d7 Home & Garden $665.59 213 0.2 52 BULK-61c7a6e8
16314 Bulk Product 45475fc9 Books $909.42 22 1.9 80 BULK-00531a69
16315 Bulk Product 23e0abd4 Toys & Games $769.84 193 1.2 28 BULK-91a36998
16316 Bulk Product 9ab13638 Clothing $599.56 229 4.1 28 BULK-50f1684e
16317 Bulk Product 856c6d02 Sports & Outdoors $643.98 253 4.4 29 BULK-fff3cd4c
16318 Bulk Product 49f8b68e Sports & Outdoors $593.63 33 1.3 30 BULK-2155af6f
16319 Bulk Product f4771e9d Home & Garden $732.23 402 3.4 17 BULK-3ad953c3
16320 Bulk Product ba65bda5 Books $252.67 355 4.8 38 BULK-92707f5b
16321 Bulk Product 0710d728 Electronics $513.04 363 4.5 41 BULK-a61c31b1
16322 Bulk Product 14f1130d Electronics $145.10 75 1.6 30 BULK-56c116f6
16323 Bulk Product 5be279bb Home & Garden $126.17 415 2.1 81 BULK-3581d30a
16324 Bulk Product 3bfc5705 Toys & Games $621.43 230 1.5 28 BULK-8c6248b5
16325 Bulk Product 866ee153 Books $686.48 239 0.8 56 BULK-43d7e3e9
16326 Bulk Product 76ceeac5 Toys & Games $453.45 378 0.2 43 BULK-53dbd250
16327 Bulk Product 3114f2f9 Sports & Outdoors $137.12 246 4.4 61 BULK-9130d270
16328 Bulk Product f668a768 Home & Garden $737.34 145 1.4 44 BULK-ae787fa4
16329 Bulk Product 170cce07 Toys & Games $777.81 118 4.4 64 BULK-b53a3251
16330 Bulk Product 68c1d39d Home & Garden $610.41 152 1.8 90 BULK-d7bf29f2
16331 Bulk Product 7f2db429 Clothing $102.05 459 3.3 85 BULK-04eb11b0
16332 Bulk Product e6a1718d Home & Garden $606.66 437 2.3 92 BULK-637964e3
16333 Bulk Product 05feee58 Home & Garden $552.99 23 2.3 27 BULK-e85d6fe2
16334 Bulk Product bc3a3260 Sports & Outdoors $18.48 427 4.6 88 BULK-41d3309d
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