Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

577 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 577 Results Showing 14401 - 14425 of 24441

ID Name Category Price Stock Rating Reviews SKU
14960 Bulk Product ccc2f966 Books $965.20 248 0.6 13 BULK-8f420f42
14961 Bulk Product 0ba20e0f Electronics $81.49 112 4.2 76 BULK-6bcbd3db
14962 Bulk Product 563c620d Home & Garden $464.44 126 0.3 5 BULK-8fe03fe5
14963 Bulk Product ebda1642 Electronics $364.86 240 0.4 97 BULK-b3aa70f4
14964 Bulk Product 0ff243c5 Sports & Outdoors $129.10 477 4.6 17 BULK-a261c99b
14965 Bulk Product e62c1272 Books $734.10 154 1.2 31 BULK-3933c97d
14966 Bulk Product a489aed4 Books $873.15 26 0.5 6 BULK-d363b45f
14967 Bulk Product 269b2e9d Home & Garden $920.90 8 0.1 79 BULK-34a38224
14968 Bulk Product 12f3dee7 Books $589.43 102 1.7 18 BULK-d8847bda
14969 Bulk Product b6625514 Clothing $676.26 143 2.0 80 BULK-1b9913e8
14970 Bulk Product 8accbeab Toys & Games $66.00 354 2.5 9 BULK-764e3e2b
14971 Bulk Product 5f6c94b0 Home & Garden $123.51 266 1.8 90 BULK-8523a48a
14972 Bulk Product 49087765 Books $695.10 120 0.3 35 BULK-3c0c282e
14973 Bulk Product 910d14d3 Electronics $282.10 156 2.0 16 BULK-309a2ba6
14974 Bulk Product a20222e6 Books $725.71 362 0.9 59 BULK-25b0afb9
14975 Bulk Product a545c15d Clothing $345.24 487 3.9 6 BULK-d342e415
14976 Bulk Product 68201aa8 Clothing $117.70 104 3.5 34 BULK-761078e5
14977 Bulk Product d20b8c96 Sports & Outdoors $727.81 73 3.1 38 BULK-5ad1e681
14978 Bulk Product 27da4758 Electronics $832.20 45 1.3 14 BULK-11484f8e
14979 Bulk Product 54ef3d12 Home & Garden $32.72 88 3.0 16 BULK-a473785f
14980 Bulk Product 84bbc820 Sports & Outdoors $47.80 462 4.8 31 BULK-789984d4
14981 Bulk Product e845d18e Toys & Games $453.50 410 1.1 37 BULK-b519ecdd
14982 Bulk Product 6b4badd7 Toys & Games $903.43 10 0.6 16 BULK-727c3660
14983 Bulk Product c1bb2bd4 Home & Garden $261.78 41 4.3 48 BULK-b97aa1f1
14984 Bulk Product 9dd65efe Home & Garden $416.69 31 0.7 19 BULK-c7b2a30a
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