Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

712 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 712 Results Showing 17776 - 17800 of 24441

ID Name Category Price Stock Rating Reviews SKU
18335 Bulk Product 4eec4f18 Books $521.93 490 0.7 87 BULK-973dc08c
18336 Bulk Product a050b96a Toys & Games $548.59 297 3.5 54 BULK-f950c5dd
18337 Bulk Product 3ffb1ae5 Books $189.40 107 0.5 32 BULK-9f1ee792
18338 Bulk Product 7781b4a1 Home & Garden $196.71 134 4.3 44 BULK-19f5b05a
18339 Bulk Product 6820f91d Books $690.34 337 0.7 70 BULK-13d46fa1
18340 Bulk Product be7c4f06 Books $262.17 163 0.9 94 BULK-8f75f5b2
18341 Bulk Product 8438ee8b Clothing $900.99 24 1.1 31 BULK-512565ba
18342 Bulk Product c4f0dec5 Electronics $581.52 241 4.3 45 BULK-7d4e64c6
18343 Bulk Product 0e835dc2 Toys & Games $939.90 137 4.1 48 BULK-614bcdfa
18344 Bulk Product ae54af01 Home & Garden $29.50 129 2.1 6 BULK-8955a759
18345 Bulk Product 65d76684 Sports & Outdoors $204.65 417 2.1 5 BULK-fb316180
18346 Bulk Product 90802966 Clothing $945.06 159 1.5 24 BULK-54b68763
18347 Bulk Product 220dc0ae Sports & Outdoors $602.69 5 2.2 17 BULK-1df153f7
18348 Bulk Product 1fe65a9b Books $480.14 344 4.9 11 BULK-27490a79
18349 Bulk Product faa3ae52 Toys & Games $871.74 335 3.7 93 BULK-955db7fd
18350 Bulk Product 7213df5d Books $638.38 413 4.8 78 BULK-ea49406d
18351 Bulk Product 695e1d45 Electronics $306.57 148 0.6 22 BULK-5ee9c631
18352 Bulk Product d3f915b7 Toys & Games $90.18 381 4.8 74 BULK-920b6c49
18353 Bulk Product d28f4a4b Home & Garden $568.74 223 0.1 63 BULK-3990ec29
18354 Bulk Product b346ded8 Home & Garden $724.88 137 4.9 54 BULK-5edd9fb3
18355 Bulk Product d05454b5 Electronics $543.75 279 3.3 79 BULK-a0e2c97c
18356 Bulk Product 244d34ea Toys & Games $1,005.40 24 1.3 31 BULK-7750ee61
18357 Bulk Product aaaa8e17 Sports & Outdoors $345.34 337 4.5 56 BULK-12f57f9c
18358 Bulk Product 139aeb0b Sports & Outdoors $942.99 317 3.2 30 BULK-ccbeae56
18359 Bulk Product 5cf0c781 Home & Garden $998.98 252 0.6 90 BULK-4087ae9f
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