Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

756 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 756 Results Showing 18876 - 18900 of 24441

ID Name Category Price Stock Rating Reviews SKU
19435 Bulk Product 5ac0ac17 Sports & Outdoors $574.55 3 2.1 18 BULK-3f65f702
19436 Bulk Product 48a2b252 Books $694.58 338 1.2 76 BULK-2671a372
19437 Bulk Product c8a418bb Clothing $266.23 38 3.7 74 BULK-7f02a155
19438 Bulk Product bcc9b063 Books $995.41 136 1.5 78 BULK-708bfb9d
19439 Bulk Product 300c8bbf Toys & Games $854.69 235 4.4 50 BULK-4b07bec4
19440 Bulk Product 8f31d760 Toys & Games $702.33 367 2.6 54 BULK-85176c6d
19441 Bulk Product 5d65544e Electronics $477.50 211 1.5 13 BULK-ec393af9
19442 Bulk Product a417383d Sports & Outdoors $799.07 265 0.1 5 BULK-b9a4d574
19443 Bulk Product 40eb98d3 Books $625.64 169 1.6 4 BULK-673a0e7f
19444 Bulk Product acd3118b Home & Garden $514.73 164 3.2 60 BULK-6d634ed5
19445 Bulk Product 5eb31aa7 Home & Garden $326.87 280 1.2 57 BULK-b5943d67
19446 Bulk Product 63d9ac5e Home & Garden $718.77 376 4.0 4 BULK-47e3d865
19447 Bulk Product aa1e10ec Sports & Outdoors $387.52 250 2.0 57 BULK-979e3cee
19448 Bulk Product f93449c0 Sports & Outdoors $339.08 336 4.0 51 BULK-5b92132b
19449 Bulk Product 1a19e987 Electronics $561.37 260 0.3 26 BULK-fe11ce1d
19450 Bulk Product 0f4717bf Clothing $501.83 64 5.0 15 BULK-afb17ab6
19451 Bulk Product cc173dff Clothing $18.23 422 3.2 84 BULK-c709594b
19452 Bulk Product b322396a Clothing $156.76 275 3.6 60 BULK-a81c77e9
19453 Bulk Product 03c9bdd2 Electronics $967.64 152 4.9 45 BULK-913a18a1
19454 Bulk Product a7c44de2 Books $515.05 297 0.5 3 BULK-9bfb73ae
19455 Bulk Product 988e1fb9 Sports & Outdoors $288.63 493 3.5 88 BULK-28da6102
19456 Bulk Product b88bd294 Sports & Outdoors $806.16 489 4.5 46 BULK-056c36f2
19457 Bulk Product be7c5bba Toys & Games $981.08 51 0.4 29 BULK-355cc634
19458 Bulk Product b9c6cd74 Sports & Outdoors $467.72 142 3.9 39 BULK-3de77894
19459 Bulk Product 22aaa222 Home & Garden $189.78 345 1.6 59 BULK-7d567eb2
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