Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

928 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 928 Results Showing 23176 - 23200 of 24441

ID Name Category Price Stock Rating Reviews SKU
23735 Bulk Product 92c6e7e3 Home & Garden $799.10 451 1.8 46 BULK-6431d3c8
23736 Bulk Product f5c69625 Home & Garden $255.24 38 4.8 71 BULK-254ccc6e
23737 Bulk Product c143e8e8 Electronics $992.02 49 3.1 44 BULK-dcc673ef
23738 Bulk Product 09fa9942 Clothing $766.53 446 0.1 3 BULK-a6b67e77
23739 Bulk Product 114b9b5e Books $652.80 190 2.3 78 BULK-aea9264b
23740 Bulk Product 88193171 Home & Garden $898.75 350 4.3 71 BULK-c5dccae7
23741 Bulk Product 6fc6bf08 Books $359.73 495 2.2 62 BULK-2c54b973
23742 Bulk Product 427bc773 Sports & Outdoors $635.85 407 0.9 63 BULK-12c5e01c
23743 Bulk Product f74f0520 Home & Garden $829.80 108 3.3 13 BULK-7f9933e3
23744 Bulk Product d868e819 Home & Garden $336.80 382 4.4 33 BULK-c1f685b1
23745 Bulk Product 1b18b154 Clothing $25.20 62 1.4 36 BULK-4d5d6345
23746 Bulk Product b5dc6df9 Sports & Outdoors $885.35 257 1.6 43 BULK-2b9d9969
23747 Bulk Product 98d9e4e6 Clothing $316.37 473 0.6 43 BULK-2ed35605
23748 Bulk Product c4156d4d Sports & Outdoors $370.16 100 3.6 89 BULK-3ff454e1
23749 Bulk Product 7e164bbc Home & Garden $871.98 164 2.9 86 BULK-c88d1e2e
23750 Bulk Product 595a6555 Clothing $622.65 66 0.2 80 BULK-19077ec4
23751 Bulk Product 4ea50db7 Toys & Games $769.02 345 2.9 18 BULK-9276eb66
23752 Bulk Product 03677ae3 Clothing $138.39 220 2.9 37 BULK-8b58613f
23753 Bulk Product 6fc85bde Books $764.88 82 1.5 88 BULK-6da2ad1d
23754 Bulk Product 46555881 Toys & Games $104.02 333 4.4 13 BULK-fb354576
23755 Bulk Product 1681b9cb Clothing $705.41 457 2.5 86 BULK-1ff29bd2
23756 Bulk Product f0941a01 Sports & Outdoors $982.31 400 3.9 24 BULK-306a6817
23757 Bulk Product 8b67fcf6 Books $146.34 287 2.0 25 BULK-fee8b32c
23758 Bulk Product 614ce5c7 Toys & Games $1,003.37 128 0.4 22 BULK-7d4af26a
23759 Bulk Product dad5d03b Sports & Outdoors $440.16 66 0.1 51 BULK-dcedee76
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