Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

43 ms

Page Size

25

Current Page

190 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 190 Results Showing 4726 - 4750 of 24441

ID Name Category Price Stock Rating Reviews SKU
5285 Bulk Product d00c1f64 Books $657.06 247 0.7 63 BULK-b0fe1550
5286 Bulk Product 52936672 Electronics $786.86 379 0.6 66 BULK-2ce23fff
5287 Bulk Product 19a6473e Books $645.34 165 2.9 90 BULK-1a584afa
5288 Bulk Product d5ccefb8 Clothing $272.85 395 4.4 6 BULK-4a04b633
5289 Bulk Product ba633a8e Books $430.32 433 3.0 22 BULK-4d044278
5290 Bulk Product 77cad251 Sports & Outdoors $466.48 250 0.9 40 BULK-9432b71e
5291 Bulk Product 1585a889 Electronics $879.70 178 1.1 82 BULK-97adb4e1
5292 Bulk Product edaab59f Home & Garden $118.85 327 0.4 61 BULK-aaddd641
5293 Bulk Product cca5dcab Sports & Outdoors $806.81 375 2.4 59 BULK-c4b3a29a
5294 Bulk Product 765027c2 Sports & Outdoors $139.80 81 2.9 51 BULK-26db3e52
5295 Bulk Product a8f789f8 Home & Garden $214.35 205 0.8 85 BULK-9f0773bf
5296 Bulk Product 14510bc4 Toys & Games $326.04 277 3.1 42 BULK-8d57ea58
5297 Bulk Product 1785ff7b Toys & Games $821.06 401 0.3 54 BULK-5987df2e
5298 Bulk Product db99ead4 Sports & Outdoors $729.64 56 1.7 12 BULK-3f543008
5299 Bulk Product 07a05b42 Books $107.67 356 3.4 65 BULK-887d1668
5300 Bulk Product a5cd7b25 Clothing $311.09 272 0.2 76 BULK-d50b1993
5301 Bulk Product 17dcf7a5 Home & Garden $879.44 165 4.1 31 BULK-0c2f7a46
5302 Bulk Product 586cb1dc Toys & Games $159.93 119 3.3 43 BULK-d425c110
5303 Bulk Product 6dad1e5b Clothing $811.61 119 3.1 38 BULK-b8b2058a
5304 Bulk Product 2aa951be Home & Garden $268.16 253 2.2 7 BULK-249778bc
5305 Bulk Product c5d6a93c Electronics $577.90 314 3.2 25 BULK-3c842529
5306 Bulk Product df455ecb Books $510.01 7 3.9 33 BULK-6949837a
5307 Bulk Product 19489e75 Toys & Games $402.52 210 4.5 3 BULK-28a40930
5308 Bulk Product afad4b3e Toys & Games $862.70 379 0.6 16 BULK-43adf1ef
5309 Bulk Product 15a6200e Electronics $328.08 351 0.5 73 BULK-904f9410
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