Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

37 ms

Page Size

25

Current Page

962 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 962 Results Showing 24026 - 24050 of 24441

ID Name Category Price Stock Rating Reviews SKU
24585 Bulk Product 3df804fc Clothing $187.24 86 0.0 56 BULK-4d257d83
24586 Bulk Product 82492be9 Books $1,002.88 276 2.0 85 BULK-57bf81a2
24587 Bulk Product 8bb0b586 Clothing $520.02 409 2.2 21 BULK-0bd453d8
24588 Bulk Product ab95eec9 Electronics $655.09 480 1.7 21 BULK-e02720d8
24589 Bulk Product 5b9c9d80 Books $309.87 212 1.1 18 BULK-28c8cd68
24590 Bulk Product 5f05024c Toys & Games $50.21 435 2.6 18 BULK-0c4de4df
24591 Bulk Product 7c25e572 Toys & Games $461.66 36 4.9 58 BULK-5f0dd580
24592 Bulk Product f9fe7a14 Electronics $329.11 363 3.0 48 BULK-3e7fcf76
24593 Bulk Product 4a1736d3 Sports & Outdoors $38.65 50 2.8 58 BULK-c02485b0
24594 Bulk Product 1cac349a Toys & Games $700.51 256 3.5 87 BULK-337a27bd
24595 Bulk Product 0d14bdad Sports & Outdoors $850.04 241 2.7 36 BULK-abc80691
24596 Bulk Product 56bf92e4 Books $408.47 161 1.2 18 BULK-861f62f0
24597 Bulk Product 580ba6f4 Home & Garden $282.30 440 4.6 52 BULK-f582ec7d
24598 Bulk Product 0a04c629 Sports & Outdoors $880.49 247 2.5 42 BULK-d52b6ef2
24599 Bulk Product d3efdcf8 Home & Garden $1,005.36 254 4.6 52 BULK-b7cc9a51
24600 Bulk Product c4e4f5bb Home & Garden $969.24 265 4.0 21 BULK-6b1af499
24601 Bulk Product 3ac41f64 Toys & Games $893.08 414 2.8 8 BULK-311a44a2
24602 Bulk Product bf442757 Toys & Games $993.68 179 0.3 20 BULK-4a8f980c
24603 Bulk Product 36a96ca2 Clothing $22.47 2 4.2 79 BULK-b28bc70a
24604 Bulk Product 85c38df1 Home & Garden $478.82 365 3.9 93 BULK-ddbff956
24605 Bulk Product 4bbf7614 Sports & Outdoors $814.64 445 0.8 84 BULK-fe181a67
24606 Bulk Product af6025ae Home & Garden $93.62 276 2.5 49 BULK-1c3ef90b
24607 Bulk Product a98b53e3 Clothing $463.78 395 3.3 91 BULK-90f66996
24608 Bulk Product 1c501d6d Sports & Outdoors $918.10 416 3.6 75 BULK-3d387b8f
24609 Bulk Product f68842f5 Clothing $822.88 249 3.3 27 BULK-39bdf177
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