Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

186 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 186 Results Showing 4626 - 4650 of 24441

ID Name Category Price Stock Rating Reviews SKU
5185 Bulk Product 6b9f3475 Toys & Games $206.61 343 3.7 90 BULK-fcfc203b
5186 Bulk Product affdc1fe Clothing $372.85 97 3.4 64 BULK-3de6becf
5187 Bulk Product 7c9cacb4 Electronics $700.45 130 1.2 11 BULK-c935f67d
5188 Bulk Product e9ad6830 Books $715.14 26 1.3 52 BULK-dec9ea81
5189 Bulk Product 6b086d6d Toys & Games $823.92 192 3.4 4 BULK-42f6549e
5190 Bulk Product 309876a5 Home & Garden $893.65 303 2.3 96 BULK-f346ed6a
5191 Bulk Product bc151280 Sports & Outdoors $501.33 29 4.8 60 BULK-e477bae4
5192 Bulk Product 648a049d Home & Garden $916.20 371 2.8 33 BULK-038cbbd0
5193 Bulk Product 201a16f5 Clothing $155.83 306 3.8 73 BULK-8e0923ae
5194 Bulk Product fbb4eea4 Toys & Games $922.29 313 4.5 94 BULK-cae3af8c
5195 Bulk Product 3b36ee2f Clothing $864.43 410 2.6 35 BULK-0075c680
5196 Bulk Product 4295e2d1 Home & Garden $265.20 76 4.6 17 BULK-fd47a22d
5197 Bulk Product 400e0e58 Books $802.35 371 1.7 90 BULK-f344b911
5198 Bulk Product f94fa08b Clothing $296.10 353 0.6 5 BULK-b7a81b25
5199 Bulk Product e5633f9f Books $940.77 365 1.9 81 BULK-aaefd73b
5200 Bulk Product f7bec455 Home & Garden $646.60 265 4.6 80 BULK-40d4d1ab
5201 Bulk Product 11c63fca Clothing $236.39 446 1.0 47 BULK-227c0c12
5202 Bulk Product 081a3d67 Home & Garden $308.04 245 2.9 26 BULK-48954389
5203 Bulk Product 52b3f743 Toys & Games $784.38 97 2.9 48 BULK-4e428242
5204 Bulk Product d6b21228 Electronics $740.75 234 0.0 73 BULK-14f99cfc
5205 Bulk Product ccc12c96 Electronics $446.45 380 3.8 93 BULK-aca92b78
5206 Bulk Product 2b10e64e Home & Garden $28.89 122 0.6 91 BULK-f39c222f
5207 Bulk Product 11e7ae36 Electronics $207.72 309 1.3 0 BULK-3992b957
5208 Bulk Product c151f5de Toys & Games $612.69 449 0.6 95 BULK-8aa4c339
5209 Bulk Product de91bc97 Toys & Games $795.05 94 2.1 30 BULK-42264533
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