Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

296 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 296 Results Showing 7376 - 7400 of 24441

ID Name Category Price Stock Rating Reviews SKU
7935 Bulk Product 7c07c2c6 Clothing $298.24 183 2.2 58 BULK-7a964741
7936 Bulk Product 7a9b89ef Clothing $140.08 182 1.8 67 BULK-50187f4c
7937 Bulk Product 2e040337 Toys & Games $372.60 407 2.7 49 BULK-cb32c19e
7938 Bulk Product a91e4399 Books $828.55 427 2.7 75 BULK-f50f8064
7939 Bulk Product 7e8e60f5 Clothing $84.01 479 4.6 64 BULK-650bb786
7940 Bulk Product d7e8bd8c Sports & Outdoors $893.03 149 3.2 72 BULK-c88a361a
7941 Bulk Product 953b247a Sports & Outdoors $35.67 369 1.2 59 BULK-179286b6
7942 Bulk Product 51faca5c Books $487.23 117 4.3 39 BULK-13f19579
7943 Bulk Product 6ad25baa Clothing $25.88 350 0.1 69 BULK-72ded161
7944 Bulk Product 3c404350 Clothing $97.33 109 2.9 24 BULK-fa6608d4
7945 Bulk Product c8bf1994 Electronics $965.77 126 0.6 31 BULK-a4819196
7946 Bulk Product 1ed0b4cf Home & Garden $276.51 396 3.4 41 BULK-7506565d
7947 Bulk Product 2337cd75 Clothing $665.33 267 2.5 68 BULK-c0ced8cc
7948 Bulk Product ecd76ead Toys & Games $222.76 478 1.8 10 BULK-871c0965
7949 Bulk Product 91121033 Home & Garden $955.47 98 3.8 55 BULK-c1aff9d9
7950 Bulk Product 2c8d3633 Electronics $684.62 235 4.8 34 BULK-ee2342cd
7951 Bulk Product 9b3e5087 Electronics $79.03 461 0.2 63 BULK-2111d9b4
7952 Bulk Product 3559cde6 Sports & Outdoors $735.03 276 2.5 18 BULK-72bcb8ce
7953 Bulk Product 231d7c44 Electronics $916.00 208 3.3 51 BULK-4669314c
7954 Bulk Product ed4fa27b Clothing $683.99 134 2.2 2 BULK-f51e0fa7
7955 Bulk Product 6c5ef4de Toys & Games $466.58 346 1.6 21 BULK-875e3fcc
7956 Bulk Product ab746070 Home & Garden $566.63 324 0.5 92 BULK-199de726
7957 Bulk Product 365e465c Sports & Outdoors $115.72 58 3.8 48 BULK-4e88600c
7958 Bulk Product 28cbc48e Books $546.13 272 4.0 98 BULK-7fd1103b
7959 Bulk Product a2c19431 Books $817.00 275 1.0 37 BULK-76adc760
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