Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

736 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 736 Results Showing 18376 - 18400 of 24441

ID Name Category Price Stock Rating Reviews SKU
18935 Bulk Product 03f6998f Sports & Outdoors $169.61 311 4.7 53 BULK-20ab030f
18936 Bulk Product 6b87456b Sports & Outdoors $254.52 273 3.2 62 BULK-e282ab64
18937 Bulk Product 3aeae30e Books $529.94 321 2.3 34 BULK-ac605a8a
18938 Bulk Product a6f5cc74 Sports & Outdoors $405.91 369 1.9 39 BULK-01235b75
18939 Bulk Product 1363eabe Books $686.81 119 0.5 82 BULK-e9871d6e
18940 Bulk Product 2e2d0924 Clothing $898.60 90 3.8 47 BULK-5d8391c4
18941 Bulk Product 44fb4272 Books $673.90 412 3.4 35 BULK-107c5388
18942 Bulk Product 2cb89f33 Electronics $157.80 179 2.7 68 BULK-27414efc
18943 Bulk Product 37620d33 Books $225.88 199 3.1 8 BULK-acb98250
18944 Bulk Product 65340c2b Toys & Games $103.57 204 3.5 90 BULK-f6613f98
18945 Bulk Product f4c0c338 Home & Garden $538.53 172 4.1 76 BULK-2d5eba1d
18946 Bulk Product 8834e9e2 Sports & Outdoors $520.98 8 0.0 26 BULK-8b58189b
18947 Bulk Product 28ed44ca Clothing $710.39 396 0.1 17 BULK-7c6798a3
18948 Bulk Product d1e94bad Toys & Games $507.87 198 4.9 29 BULK-adf300be
18949 Bulk Product c55b5342 Home & Garden $374.53 252 2.5 96 BULK-96cd3b86
18950 Bulk Product 64795ff7 Sports & Outdoors $294.21 408 4.6 42 BULK-8dc522e3
18951 Bulk Product 20b458dc Sports & Outdoors $460.13 82 1.7 62 BULK-0aabc91e
18952 Bulk Product b15820be Home & Garden $19.45 376 0.8 47 BULK-d7a3169a
18953 Bulk Product a88b5872 Clothing $388.88 421 2.7 54 BULK-91f6fe26
18954 Bulk Product 1dd23560 Toys & Games $793.17 472 1.7 97 BULK-5fd8781c
18955 Bulk Product 74a53e19 Electronics $339.75 366 5.0 1 BULK-ec1414f9
18956 Bulk Product 32ac4224 Books $919.30 108 3.3 20 BULK-640120d7
18957 Bulk Product c608160f Electronics $443.57 66 0.0 71 BULK-27bbd103
18958 Bulk Product 398d02b2 Electronics $853.06 174 2.6 43 BULK-9afc56fd
18959 Bulk Product 2ffdc8d6 Toys & Games $77.44 232 5.0 41 BULK-1143c432
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