Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

617 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 617 Results Showing 15401 - 15425 of 24441

ID Name Category Price Stock Rating Reviews SKU
15960 Bulk Product d719bc25 Books $317.50 224 0.4 53 BULK-c48dd436
15961 Bulk Product 87ce5037 Home & Garden $819.82 24 1.9 7 BULK-d2a34be4
15962 Bulk Product ac40f892 Electronics $157.43 203 2.1 60 BULK-08ab13f4
15963 Bulk Product c563a059 Home & Garden $455.34 468 3.1 90 BULK-b1d9b9e7
15964 Bulk Product fd673bc6 Clothing $854.16 64 1.4 24 BULK-1b5ca8dc
15965 Bulk Product e8d585b0 Clothing $990.29 114 0.7 9 BULK-8671266d
15966 Bulk Product 4c395e5c Books $533.28 487 4.1 42 BULK-b2d2a01c
15967 Bulk Product 7509e699 Clothing $761.75 467 0.3 44 BULK-93a6259f
15968 Bulk Product 15ec2147 Books $690.69 461 0.3 9 BULK-48a1be14
15969 Bulk Product 3a169c28 Electronics $271.25 194 3.1 49 BULK-40998e7d
15970 Bulk Product 3b6f428d Electronics $350.96 139 5.0 67 BULK-6f10fcea
15971 Bulk Product b7564f88 Books $204.57 190 4.0 40 BULK-ffa3ccfd
15972 Bulk Product f95d5ccd Books $136.41 142 3.9 43 BULK-b65b395a
15973 Bulk Product 8a93f990 Clothing $140.61 367 3.5 38 BULK-a46895f9
15974 Bulk Product 8f68799d Home & Garden $955.40 206 2.3 32 BULK-b6ca1751
15975 Bulk Product 6cab9dbe Books $314.54 250 0.9 93 BULK-d0d7c5b1
15976 Bulk Product 32bf5bda Electronics $294.12 83 0.4 50 BULK-c815561a
15977 Bulk Product 43c5041a Home & Garden $114.70 378 0.0 92 BULK-eb8e5ccf
15978 Bulk Product 9dca561c Books $300.30 456 4.6 15 BULK-bc8871b8
15979 Bulk Product 9aebcbcf Electronics $342.22 400 2.3 20 BULK-d2a42a2b
15980 Bulk Product ac8cdf01 Clothing $431.90 222 4.2 21 BULK-34226ba1
15981 Bulk Product ab46e8e0 Books $31.42 193 3.9 53 BULK-74b1b253
15982 Bulk Product 89af4d3e Sports & Outdoors $555.75 238 3.9 60 BULK-48341ca0
15983 Bulk Product 5da53232 Home & Garden $50.42 18 1.9 11 BULK-721d45bf
15984 Bulk Product 6cbe0489 Books $894.22 373 2.2 7 BULK-de1a03d5
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