Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

952 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 952 Results Showing 23776 - 23800 of 24441

ID Name Category Price Stock Rating Reviews SKU
24335 Bulk Product b9b4498a Toys & Games $945.92 231 2.1 11 BULK-c019f215
24336 Bulk Product f61f0a5c Clothing $628.49 304 3.2 25 BULK-8bbce299
24337 Bulk Product 16852ebb Home & Garden $363.06 461 4.3 19 BULK-845081b5
24338 Bulk Product 95634f5e Electronics $541.91 442 4.9 98 BULK-9a894dbe
24339 Bulk Product af13dae3 Sports & Outdoors $712.77 102 4.8 39 BULK-31ddcb93
24340 Bulk Product c083ffb3 Sports & Outdoors $392.27 99 0.9 72 BULK-50939876
24341 Bulk Product a498e1e7 Electronics $772.67 154 2.7 57 BULK-d1665dcf
24342 Bulk Product 1444082e Home & Garden $305.85 180 5.0 46 BULK-48f2a3f0
24343 Bulk Product c288e3c5 Books $330.39 78 4.7 65 BULK-98515b63
24344 Bulk Product 73b6fd69 Sports & Outdoors $984.87 390 3.7 17 BULK-ade72c93
24345 Bulk Product dffb1ddb Books $376.35 406 3.9 89 BULK-729a244f
24346 Bulk Product 9b509d5c Toys & Games $138.41 93 0.4 27 BULK-664f7077
24347 Bulk Product a39c1435 Toys & Games $644.55 279 2.3 15 BULK-fe5d31dc
24348 Bulk Product 52932d1f Clothing $878.25 391 4.2 23 BULK-624bdd3f
24349 Bulk Product 3c4e6a86 Sports & Outdoors $166.38 453 4.0 45 BULK-abe6a7f8
24350 Bulk Product 589cc1cc Sports & Outdoors $862.58 395 3.3 25 BULK-d09bd8bb
24351 Bulk Product e39b0a78 Home & Garden $600.34 282 2.6 48 BULK-16193b44
24352 Bulk Product 8a97874d Toys & Games $70.12 18 0.9 43 BULK-7b1ccc9c
24353 Bulk Product c4941afc Home & Garden $783.10 94 2.8 71 BULK-f0440643
24354 Bulk Product 4126fe52 Toys & Games $284.63 114 3.4 60 BULK-ef7cf65e
24355 Bulk Product 2ca7d36c Electronics $861.68 253 3.3 54 BULK-124ebfa9
24356 Bulk Product ff10d1f0 Toys & Games $10.08 489 0.1 30 BULK-8919e7fe
24357 Bulk Product af438a15 Sports & Outdoors $380.42 8 0.3 8 BULK-d8951a32
24358 Bulk Product bace0c95 Toys & Games $899.27 104 4.8 35 BULK-fadfd483
24359 Bulk Product 353f436a Clothing $48.42 463 3.3 24 BULK-d83171c9
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