Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

33 ms

Page Size

25

Current Page

696 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 696 Results Showing 17376 - 17400 of 24441

ID Name Category Price Stock Rating Reviews SKU
17935 Bulk Product 124bf923 Electronics $250.90 219 0.0 10 BULK-5f42a94c
17936 Bulk Product edd72687 Clothing $326.64 82 1.0 61 BULK-5d740844
17937 Bulk Product cbabef98 Home & Garden $848.67 370 3.0 66 BULK-b39ffcda
17938 Bulk Product 31d1f8f3 Toys & Games $793.12 308 2.4 41 BULK-2a10c01b
17939 Bulk Product c2b769b9 Clothing $832.77 385 0.3 46 BULK-7852577d
17940 Bulk Product 9fee2aa4 Home & Garden $431.61 406 3.8 75 BULK-f25b9fd1
17941 Bulk Product a14f3821 Home & Garden $462.76 172 4.7 52 BULK-2d045002
17942 Bulk Product 168a6461 Clothing $266.32 39 2.4 11 BULK-14bef908
17943 Bulk Product cad83db2 Clothing $1,002.98 487 0.6 57 BULK-d6799d9f
17944 Bulk Product 563f418c Home & Garden $107.43 89 0.1 82 BULK-002cbf6d
17945 Bulk Product 0b088a20 Electronics $866.14 300 1.8 34 BULK-8890d9ac
17946 Bulk Product 78aea71d Electronics $326.76 466 1.6 6 BULK-a0c122be
17947 Bulk Product a320c3b5 Sports & Outdoors $979.27 1 2.8 92 BULK-42e40515
17948 Bulk Product fd426bb7 Home & Garden $902.25 200 1.1 72 BULK-4760a70d
17949 Bulk Product 67b4b6be Electronics $418.70 312 2.1 72 BULK-4a1130d7
17950 Bulk Product 8eae719b Sports & Outdoors $833.62 177 1.8 93 BULK-9416c491
17951 Bulk Product 3106b377 Books $949.54 359 1.2 91 BULK-a68abac1
17952 Bulk Product 5d4715cb Electronics $519.17 287 4.5 27 BULK-05b3a7bb
17953 Bulk Product 7d48726d Sports & Outdoors $673.25 396 1.2 12 BULK-547ab3ea
17954 Bulk Product b1bbb436 Books $260.29 95 4.5 97 BULK-82731d4e
17955 Bulk Product 80047601 Home & Garden $125.59 302 1.0 39 BULK-7a1cfb0a
17956 Bulk Product dc1ceedf Books $702.32 243 4.1 79 BULK-907d1dd9
17957 Bulk Product d530e3ba Toys & Games $34.19 9 3.6 50 BULK-9eb140bb
17958 Bulk Product fac925ed Electronics $894.79 356 1.9 73 BULK-d4c0c695
17959 Bulk Product ccc3e024 Clothing $23.03 144 4.4 23 BULK-ffa02539
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