Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

613 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 613 Results Showing 15301 - 15325 of 24441

ID Name Category Price Stock Rating Reviews SKU
15860 Bulk Product d1b4bbd8 Home & Garden $572.38 2 0.8 44 BULK-0b4c370a
15861 Bulk Product 930e768c Books $142.19 22 0.8 94 BULK-59f9b2cd
15862 Bulk Product 63cc3cfa Home & Garden $533.12 406 0.1 40 BULK-f46327d9
15863 Bulk Product 90c15a2b Books $318.25 275 1.3 2 BULK-5a78df9b
15864 Bulk Product 3f234a8a Electronics $55.03 161 1.2 85 BULK-fa332134
15865 Bulk Product 98dc286e Toys & Games $410.48 278 5.0 76 BULK-2da84070
15866 Bulk Product d76a5c63 Electronics $905.83 397 2.5 4 BULK-3c5f68ef
15867 Bulk Product 7d7c8937 Sports & Outdoors $276.52 473 2.3 1 BULK-11627582
15868 Bulk Product 0815961f Electronics $823.52 280 4.8 14 BULK-d423df7c
15869 Bulk Product 85fceee8 Home & Garden $380.04 389 4.5 80 BULK-ffb0a082
15870 Bulk Product f2e39606 Clothing $466.64 395 0.5 4 BULK-ac034672
15871 Bulk Product ad5d3888 Electronics $382.49 182 4.5 23 BULK-bf2c20fd
15872 Bulk Product c9268f5d Toys & Games $671.24 470 2.6 79 BULK-648a3f60
15873 Bulk Product 802a9b33 Home & Garden $513.82 271 2.5 97 BULK-f81c3195
15874 Bulk Product 7252cf8e Clothing $68.61 450 3.4 69 BULK-30756bd3
15875 Bulk Product 3162cf75 Books $482.10 37 4.3 68 BULK-b13ddd21
15876 Bulk Product 3291f0c4 Clothing $131.01 237 0.7 45 BULK-a0d2103a
15877 Bulk Product a2fa0172 Sports & Outdoors $226.59 258 0.7 77 BULK-4ed89358
15878 Bulk Product e19a5a53 Electronics $953.01 70 2.5 78 BULK-18576aa0
15879 Bulk Product 55e8ea8d Electronics $305.10 307 0.6 9 BULK-d96dd0e8
15880 Bulk Product c627b382 Sports & Outdoors $316.71 291 3.5 57 BULK-ceb5cf4b
15881 Bulk Product 758ee81f Home & Garden $935.27 45 2.2 77 BULK-1fe1beaf
15882 Bulk Product 62aaa215 Electronics $658.21 107 2.3 1 BULK-74124b22
15883 Bulk Product 5ac7e656 Clothing $648.27 168 3.5 30 BULK-bde60bd4
15884 Bulk Product d424e0f8 Clothing $162.17 199 0.3 33 BULK-2c6fbaf5
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