Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

518 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 518 Results Showing 12926 - 12950 of 24441

ID Name Category Price Stock Rating Reviews SKU
13485 Bulk Product 7848e78b Toys & Games $865.37 383 3.8 66 BULK-60cb198f
13486 Bulk Product 26440c8b Electronics $155.73 329 2.2 99 BULK-451ea422
13487 Bulk Product a643dc0f Clothing $297.27 258 3.6 46 BULK-e64fa538
13488 Bulk Product 62c3fa7c Books $758.11 350 3.5 27 BULK-9ddeccf2
13489 Bulk Product 83a10762 Sports & Outdoors $988.23 177 3.1 64 BULK-8307959a
13490 Bulk Product f8c28a9a Electronics $107.44 182 1.3 53 BULK-ec5a1677
13491 Bulk Product 041464c3 Home & Garden $66.65 270 4.0 35 BULK-970f0140
13492 Bulk Product 2c71fc14 Books $263.79 199 2.2 61 BULK-596c466c
13493 Bulk Product 03179631 Sports & Outdoors $872.65 145 1.3 35 BULK-3cb9e5e3
13494 Bulk Product 401e7401 Electronics $932.50 480 0.1 78 BULK-3b3bdea5
13495 Bulk Product 5d259770 Toys & Games $224.61 158 1.3 24 BULK-99685298
13496 Bulk Product 3d4e859e Toys & Games $186.43 82 2.3 2 BULK-a059e9c9
13497 Bulk Product 9193156a Sports & Outdoors $216.68 334 1.7 39 BULK-71da00ad
13498 Bulk Product ffa01eea Sports & Outdoors $549.95 168 3.4 87 BULK-862b76c9
13499 Bulk Product ac894dbf Electronics $593.83 61 4.8 99 BULK-88ca13f7
13500 Bulk Product d4363e68 Books $496.82 399 2.6 33 BULK-c8fcefb1
13501 Bulk Product 1458e696 Clothing $874.63 129 3.6 14 BULK-55ba7514
13502 Bulk Product 5796c8ed Clothing $542.09 100 4.9 43 BULK-5a69e188
13503 Bulk Product 45369a49 Sports & Outdoors $456.86 140 1.7 69 BULK-5d77694d
13504 Bulk Product 13d6cec8 Books $226.81 51 0.9 13 BULK-ddfeaebf
13505 Bulk Product d284f390 Clothing $412.70 345 0.4 98 BULK-da8e0178
13506 Bulk Product 56be4f42 Electronics $107.44 242 2.5 43 BULK-0c47ee38
13507 Bulk Product 340a98ba Books $84.65 216 3.6 55 BULK-0b2b92d7
13508 Bulk Product 57c30e32 Toys & Games $652.47 479 2.2 50 BULK-6010a6ae
13509 Bulk Product 46146989 Home & Garden $942.56 4 0.3 8 BULK-6077462a
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