Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

54 ms

Page Size

25

Current Page

188 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 188 Results Showing 4676 - 4700 of 24441

ID Name Category Price Stock Rating Reviews SKU
5235 Bulk Product 0a950b03 Home & Garden $258.08 144 0.9 42 BULK-c016d96a
5236 Bulk Product 09a59f33 Home & Garden $735.97 395 2.7 7 BULK-1a7632ac
5237 Bulk Product 7e76caa8 Toys & Games $970.71 360 1.3 14 BULK-b3bc1c47
5238 Bulk Product 916821a7 Sports & Outdoors $78.49 104 1.5 21 BULK-cbd727e1
5239 Bulk Product 48f9fece Home & Garden $733.87 488 2.9 9 BULK-e753d883
5240 Bulk Product 392080e9 Home & Garden $823.27 37 3.9 68 BULK-d791fa09
5241 Bulk Product c78ffd97 Sports & Outdoors $667.47 272 1.8 53 BULK-98157fab
5242 Bulk Product e62103a5 Electronics $424.48 481 4.0 12 BULK-389814cb
5243 Bulk Product 3b5a8321 Clothing $509.26 375 0.0 14 BULK-2e650415
5244 Bulk Product 18d583ea Toys & Games $14.36 477 4.4 93 BULK-1fb6b527
5245 Bulk Product c85bce04 Toys & Games $692.30 481 5.0 94 BULK-d9a63527
5246 Bulk Product 12b8d844 Toys & Games $412.78 494 1.2 52 BULK-5e3bbc96
5247 Bulk Product f9fa5324 Clothing $425.27 411 2.9 15 BULK-eed94705
5248 Bulk Product ef381b71 Electronics $529.57 277 2.0 54 BULK-17b73a33
5249 Bulk Product 4ea92183 Home & Garden $121.08 36 3.3 96 BULK-4842734e
5250 Bulk Product 3d1d926a Toys & Games $607.08 377 1.4 14 BULK-e4842470
5251 Bulk Product b65e7b23 Electronics $794.81 228 0.9 90 BULK-d93dd7ca
5252 Bulk Product 3ddb6256 Clothing $774.40 71 1.8 38 BULK-17c76621
5253 Bulk Product bfd4818c Home & Garden $985.23 18 4.6 81 BULK-014fbf6f
5254 Bulk Product a81b80d5 Books $89.73 150 4.5 67 BULK-89e6eaf7
5255 Bulk Product e7a56ed9 Home & Garden $459.55 486 0.8 4 BULK-069e2366
5256 Bulk Product 646eb1a8 Books $961.19 37 4.7 30 BULK-f00f604c
5257 Bulk Product 6e1fb087 Books $436.94 206 2.8 26 BULK-95bfa32c
5258 Bulk Product 43321864 Home & Garden $1,007.24 313 3.4 41 BULK-d67becbf
5259 Bulk Product 5bc99a55 Books $1,009.85 92 3.9 15 BULK-68619bf2
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