Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

627 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 627 Results Showing 15651 - 15675 of 24441

ID Name Category Price Stock Rating Reviews SKU
16210 Bulk Product a2487b72 Home & Garden $285.40 339 1.7 21 BULK-e5437aec
16211 Bulk Product 0cba40fc Clothing $433.51 309 3.1 95 BULK-a9601d78
16212 Bulk Product aa60f7b2 Home & Garden $800.27 278 2.4 30 BULK-cfafcbc3
16213 Bulk Product 6e16b71b Electronics $564.59 388 5.0 94 BULK-8e5f06c5
16214 Bulk Product 6985f7fe Books $199.48 289 1.4 22 BULK-56adad1c
16215 Bulk Product c8eee4de Toys & Games $381.24 321 3.8 75 BULK-abf53ecc
16216 Bulk Product 069d478a Home & Garden $209.90 107 1.5 52 BULK-4ddb78a2
16217 Bulk Product 5cdd1d16 Electronics $467.23 66 2.5 83 BULK-90ca8566
16218 Bulk Product c41e64d0 Home & Garden $525.43 184 4.1 58 BULK-e0a5cdc4
16219 Bulk Product 862be6b4 Books $59.59 360 3.5 64 BULK-ee4614f4
16220 Bulk Product 4686fde6 Sports & Outdoors $943.46 40 4.4 41 BULK-4f97ad1f
16221 Bulk Product 2849efe3 Electronics $517.33 110 1.8 94 BULK-e9042468
16222 Bulk Product 140d8475 Home & Garden $46.09 257 4.6 55 BULK-8247363c
16223 Bulk Product 3b72d261 Home & Garden $558.27 408 4.5 29 BULK-c279b178
16224 Bulk Product 506cffb8 Sports & Outdoors $988.68 258 0.3 27 BULK-1b1bccef
16225 Bulk Product 46e61b3d Sports & Outdoors $25.62 112 3.5 10 BULK-36e8714e
16226 Bulk Product f1a1985f Toys & Games $860.37 94 3.1 43 BULK-de8f3c47
16227 Bulk Product 91f50981 Toys & Games $617.50 453 0.8 25 BULK-8bb670f8
16228 Bulk Product 2c5cdf72 Electronics $475.03 163 4.4 13 BULK-3df31bf4
16229 Bulk Product 1a9ebe0f Toys & Games $246.72 290 2.7 10 BULK-a73e7775
16230 Bulk Product f6d7d7ef Sports & Outdoors $976.15 280 3.0 21 BULK-73b84a40
16231 Bulk Product 705975d2 Toys & Games $250.70 339 1.0 76 BULK-3ec463b1
16232 Bulk Product d6399414 Sports & Outdoors $635.32 70 2.1 94 BULK-348f5cdf
16233 Bulk Product 75470f72 Clothing $108.93 435 0.9 64 BULK-fa0e503c
16234 Bulk Product fe6a9d94 Sports & Outdoors $105.94 60 4.1 0 BULK-9ad3538b
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