Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

36 ms

Page Size

25

Current Page

285 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 285 Results Showing 7101 - 7125 of 24441

ID Name Category Price Stock Rating Reviews SKU
7660 Bulk Product b3ea80b9 Books $48.99 85 3.3 48 BULK-ca813dce
7661 Bulk Product 23753e83 Sports & Outdoors $868.97 458 1.6 72 BULK-26c1f6bd
7662 Bulk Product cabd91f0 Electronics $346.71 451 2.8 23 BULK-2f5cf010
7663 Bulk Product 8a62f82b Sports & Outdoors $507.53 136 2.0 72 BULK-1d591909
7664 Bulk Product 1a4eba57 Clothing $120.79 459 5.0 36 BULK-1bfb603a
7665 Bulk Product 2d86a094 Clothing $576.60 341 1.5 20 BULK-84155dcd
7666 Bulk Product 9a57d84e Toys & Games $992.31 205 3.3 78 BULK-5ad9521e
7667 Bulk Product 9924a242 Toys & Games $491.27 145 3.4 35 BULK-87351028
7668 Bulk Product 0094d4e8 Electronics $624.23 42 2.9 87 BULK-c698a23f
7669 Bulk Product f2c42ee4 Books $174.68 72 2.5 63 BULK-8b28b19b
7670 Bulk Product 64f2f52b Home & Garden $923.18 66 2.5 61 BULK-d0da6a66
7671 Bulk Product d62e6e1c Electronics $912.36 1 3.9 43 BULK-3ecff0e6
7672 Bulk Product b0da142d Sports & Outdoors $132.13 130 0.2 69 BULK-48e22743
7673 Bulk Product a992a584 Electronics $13.37 468 0.7 32 BULK-659d3d61
7674 Bulk Product 0d2f1d2e Sports & Outdoors $205.47 203 1.4 39 BULK-01369688
7675 Bulk Product e1a2a121 Electronics $901.60 418 3.8 66 BULK-0a5d08f8
7676 Bulk Product a61834be Toys & Games $31.95 113 4.4 42 BULK-d1b3f6de
7677 Bulk Product 4f639c84 Home & Garden $123.03 123 4.6 73 BULK-8e735e29
7678 Bulk Product cddee4e1 Books $974.21 45 2.6 23 BULK-8178cd2b
7679 Bulk Product 791f5161 Home & Garden $52.96 159 4.5 37 BULK-63fea041
7680 Bulk Product a03d466a Clothing $626.45 276 0.7 68 BULK-d5ebf8db
7681 Bulk Product cce64aab Sports & Outdoors $658.02 404 3.6 96 BULK-10c6f833
7682 Bulk Product d9a59d05 Toys & Games $115.96 162 0.2 70 BULK-b09ddd8a
7683 Bulk Product de37b128 Clothing $706.72 116 1.6 78 BULK-1b2a3d92
7684 Bulk Product 8f9f7840 Toys & Games $91.75 163 2.9 3 BULK-1684021d
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