Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

865 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 865 Results Showing 21601 - 21625 of 24441

ID Name Category Price Stock Rating Reviews SKU
22160 Bulk Product 75a8ea37 Electronics $506.13 68 2.5 27 BULK-7f33c4e5
22161 Bulk Product 0a820ea4 Sports & Outdoors $348.71 410 0.2 33 BULK-50562075
22162 Bulk Product 82dc5f16 Toys & Games $541.25 152 0.4 15 BULK-698fd751
22163 Bulk Product db79eec7 Sports & Outdoors $634.88 447 2.4 72 BULK-431f919e
22164 Bulk Product 8c309d48 Clothing $966.73 196 3.6 39 BULK-4eee4c54
22165 Bulk Product e15b4a1c Electronics $251.52 402 2.1 76 BULK-6b0d60d5
22166 Bulk Product 5321c58b Sports & Outdoors $106.43 143 3.6 97 BULK-7a68424a
22167 Bulk Product 5ffa2da8 Electronics $524.26 368 0.4 45 BULK-f1fd3ee1
22168 Bulk Product 441617bc Clothing $725.99 145 3.5 40 BULK-3c9aa227
22169 Bulk Product 0de75e5d Toys & Games $885.04 362 1.6 68 BULK-be155f0b
22170 Bulk Product 8a5e4fe2 Books $164.59 18 2.5 67 BULK-e4b23c07
22171 Bulk Product ae517af7 Electronics $905.63 265 1.2 43 BULK-cec112ab
22172 Bulk Product 49a0fd8b Toys & Games $795.44 405 4.0 32 BULK-2f9f1c8b
22173 Bulk Product a499966d Books $230.60 179 1.4 61 BULK-fa2dc122
22174 Bulk Product dfe6a782 Toys & Games $537.63 217 4.9 14 BULK-96997934
22175 Bulk Product bfa5ba11 Clothing $974.19 440 0.1 26 BULK-4b8aa13d
22176 Bulk Product b5b0cc65 Home & Garden $566.33 118 2.5 35 BULK-2039f530
22177 Bulk Product 714daf38 Toys & Games $108.60 442 3.0 97 BULK-90a6aadb
22178 Bulk Product ec9cd5c1 Sports & Outdoors $138.75 153 3.7 45 BULK-b89f96d4
22179 Bulk Product 03f7ddc9 Toys & Games $271.51 189 4.0 6 BULK-35d4a10f
22180 Bulk Product 54394a3d Toys & Games $64.83 224 3.4 54 BULK-b40fc626
22181 Bulk Product 3eabbbf8 Electronics $829.13 422 0.8 42 BULK-b4a858d7
22182 Bulk Product ccbb11dd Books $908.42 126 0.7 23 BULK-28b3da32
22183 Bulk Product f44110f0 Clothing $595.81 60 1.0 87 BULK-ea9780a7
22184 Bulk Product dc0ff3fa Electronics $583.83 370 1.8 29 BULK-3ca334dc
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