Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

761 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 761 Results Showing 19001 - 19025 of 24441

ID Name Category Price Stock Rating Reviews SKU
19560 Bulk Product 3fb4b7f5 Home & Garden $109.33 357 4.6 22 BULK-8d4e66b2
19561 Bulk Product 4817cb53 Sports & Outdoors $1,003.02 81 2.9 85 BULK-9f48969d
19562 Bulk Product 3cf021de Sports & Outdoors $827.33 389 0.2 79 BULK-fb27506f
19563 Bulk Product 6e0578db Electronics $662.76 240 3.4 53 BULK-9e00b135
19564 Bulk Product 4ecc7976 Sports & Outdoors $746.42 19 4.0 1 BULK-988b813f
19565 Bulk Product 468aa134 Electronics $745.23 111 4.0 46 BULK-b1462d40
19566 Bulk Product f5560876 Electronics $860.30 102 1.7 11 BULK-f688bcb3
19567 Bulk Product 488cff0f Electronics $447.23 204 3.2 37 BULK-e2dddb14
19568 Bulk Product 85d559a4 Clothing $406.96 210 3.7 31 BULK-511ad65b
19569 Bulk Product 85dcf03b Sports & Outdoors $511.96 121 2.2 99 BULK-c8cd7bd8
19570 Bulk Product 7b487ab3 Clothing $41.69 85 0.1 31 BULK-f74dc43f
19571 Bulk Product 1e78adb1 Books $278.20 16 2.6 18 BULK-1f3f0ddd
19572 Bulk Product acc3068c Books $56.06 72 3.7 59 BULK-84633d51
19573 Bulk Product db11bf27 Books $514.79 210 2.8 60 BULK-ad1ad11f
19574 Bulk Product 94682178 Electronics $338.27 66 2.5 13 BULK-216f3bd1
19575 Bulk Product d46e0849 Sports & Outdoors $963.04 377 2.4 2 BULK-cffa8d63
19576 Bulk Product db5827b9 Clothing $74.65 93 2.5 92 BULK-a3327589
19577 Bulk Product 3363187d Clothing $248.21 148 2.3 18 BULK-11b026f7
19578 Bulk Product 7d947f3c Electronics $657.35 130 4.2 97 BULK-f787f4a8
19579 Bulk Product 8d9c7a4b Electronics $895.77 362 2.6 8 BULK-89b6e103
19580 Bulk Product 1e8b7e0a Toys & Games $23.68 397 2.2 50 BULK-9baa038b
19581 Bulk Product 1cedf206 Clothing $205.03 412 3.9 32 BULK-990c0bd2
19582 Bulk Product 71a76953 Electronics $907.06 60 0.4 86 BULK-40caea3d
19583 Bulk Product 1338b394 Electronics $866.74 263 3.4 30 BULK-14ccfe33
19584 Bulk Product 2d5e7473 Sports & Outdoors $901.46 194 2.3 51 BULK-d20541b9
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