Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

179 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 179 Results Showing 4451 - 4475 of 24441

ID Name Category Price Stock Rating Reviews SKU
5010 Bulk Product f98c3e27 Clothing $161.78 339 2.9 17 BULK-c58e5f44
5011 Bulk Product 89ebec4c Toys & Games $964.34 245 2.5 37 BULK-bb44277c
5012 Bulk Product 9753e3be Books $672.53 221 2.7 4 BULK-aca7b6b2
5013 Bulk Product 4ea9e620 Books $734.15 150 3.3 30 BULK-c30540de
5014 Bulk Product a35990d0 Books $243.29 187 3.3 87 BULK-a9a8a1ba
5015 Bulk Product c096b777 Clothing $670.92 102 0.4 67 BULK-1d694d6c
5016 Bulk Product 594deefe Books $507.41 480 4.1 47 BULK-ee1bc3a8
5017 Bulk Product 91cadee9 Electronics $607.25 395 1.6 63 BULK-c42bafa9
5018 Bulk Product 287a2007 Sports & Outdoors $467.67 33 4.4 2 BULK-786c667f
5019 Bulk Product 76e229ba Electronics $387.20 274 2.8 99 BULK-a4e19a22
5020 Bulk Product 2f6aea12 Toys & Games $776.37 0 4.9 7 BULK-642efb7f
5021 Bulk Product 0f0cb0d5 Toys & Games $240.36 16 2.5 8 BULK-3c42e4af
5022 Bulk Product 07511384 Clothing $127.25 126 5.0 14 BULK-7c393ab4
5023 Bulk Product 94ea15e1 Home & Garden $366.24 32 0.5 33 BULK-8b321003
5024 Bulk Product df630e59 Books $649.66 280 3.3 53 BULK-b5329708
5025 Bulk Product 3198a817 Home & Garden $710.30 358 2.0 3 BULK-f4d7f10a
5026 Bulk Product fa17ac53 Sports & Outdoors $993.51 201 2.4 31 BULK-af4388b0
5027 Bulk Product 9e018c01 Toys & Games $24.30 228 1.9 44 BULK-610f52a9
5028 Bulk Product e73aa39e Toys & Games $530.87 429 3.5 4 BULK-8b1a23c2
5029 Bulk Product 10c84a38 Home & Garden $817.77 47 4.2 21 BULK-ad4eba29
5030 Bulk Product 8e880685 Electronics $627.06 423 3.0 30 BULK-6729084d
5031 Bulk Product 7f1beec9 Home & Garden $62.55 472 4.5 54 BULK-84a28e52
5032 Bulk Product 53e50afa Sports & Outdoors $243.62 230 4.9 62 BULK-056a2656
5033 Bulk Product 7ba1066f Sports & Outdoors $557.31 486 1.3 23 BULK-b92dfb82
5034 Bulk Product ec899341 Sports & Outdoors $620.86 447 2.3 40 BULK-098fc90d
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