Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

30 ms

Page Size

25

Current Page

884 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 884 Results Showing 22076 - 22100 of 24441

ID Name Category Price Stock Rating Reviews SKU
22635 Bulk Product 2f31fb38 Books $481.20 150 2.1 46 BULK-bc69d34c
22636 Bulk Product 35f83ff7 Home & Garden $843.70 97 4.8 40 BULK-09f6ab26
22637 Bulk Product 899cde2b Sports & Outdoors $803.49 241 1.3 83 BULK-51eb4c34
22638 Bulk Product b59feef9 Electronics $661.04 220 2.9 95 BULK-a2bc933e
22639 Bulk Product 1e7d08ff Sports & Outdoors $321.28 98 2.1 50 BULK-dee46f04
22640 Bulk Product e7a831f0 Home & Garden $32.73 394 3.3 84 BULK-ef331a0e
22641 Bulk Product 8634f659 Toys & Games $506.85 264 3.8 45 BULK-13d1b062
22642 Bulk Product cc777ea0 Home & Garden $133.28 10 1.0 55 BULK-51ddad6f
22643 Bulk Product 483d9231 Clothing $771.43 165 2.0 85 BULK-bc930629
22644 Bulk Product 2b0fb81f Clothing $633.94 53 4.6 77 BULK-b47f2d8d
22645 Bulk Product 175663a3 Home & Garden $161.88 346 5.0 80 BULK-100b6f74
22646 Bulk Product 56af5038 Sports & Outdoors $45.65 291 3.3 1 BULK-dbf96082
22647 Bulk Product 89e4e63b Clothing $457.11 39 4.7 75 BULK-9b453ec5
22648 Bulk Product c2a31238 Electronics $628.06 344 2.6 81 BULK-a39f13a4
22649 Bulk Product 25b0ebd0 Electronics $904.28 243 1.0 83 BULK-d784e839
22650 Bulk Product eeb656eb Sports & Outdoors $309.65 205 0.7 7 BULK-051270f7
22651 Bulk Product 74b7a39f Books $732.83 476 2.2 96 BULK-6c3cf099
22652 Bulk Product cd129e7f Books $228.52 73 1.0 32 BULK-25642b6f
22653 Bulk Product 41c91ee1 Electronics $114.65 424 4.2 42 BULK-c4eb6f75
22654 Bulk Product 67ec3c8d Sports & Outdoors $918.06 414 3.1 9 BULK-91df5e86
22655 Bulk Product 19d05312 Books $736.09 132 2.5 43 BULK-f8e951ae
22656 Bulk Product 76dde920 Books $338.69 406 3.3 71 BULK-1461490b
22657 Bulk Product 2bfa0fc9 Books $103.22 409 1.2 45 BULK-817218f8
22658 Bulk Product 2f58baa8 Sports & Outdoors $294.75 354 3.5 21 BULK-ab713ffd
22659 Bulk Product 113d8ba9 Home & Garden $753.72 87 3.7 13 BULK-7e75bb4e
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