Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

860 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 860 Results Showing 21476 - 21500 of 24441

ID Name Category Price Stock Rating Reviews SKU
22035 Bulk Product 0f8b0231 Clothing $25.97 452 0.9 73 BULK-00c17bb1
22036 Bulk Product d6675e53 Clothing $599.84 495 0.3 41 BULK-82ac3227
22037 Bulk Product 3e5b88d9 Books $104.32 493 4.1 52 BULK-dda86f9f
22038 Bulk Product 905e7b9f Clothing $445.93 351 3.0 66 BULK-09ed434b
22039 Bulk Product 4ae19292 Sports & Outdoors $69.75 363 3.3 89 BULK-88a63a8a
22040 Bulk Product 9e935279 Electronics $117.18 390 1.6 22 BULK-ed3ec913
22041 Bulk Product 768c8a0d Sports & Outdoors $406.68 376 3.8 62 BULK-ae947be3
22042 Bulk Product dbb4dcda Clothing $115.63 413 2.3 51 BULK-a645c66d
22043 Bulk Product 82815b58 Electronics $752.95 120 4.2 28 BULK-25cc8269
22044 Bulk Product 71d4d7df Electronics $136.78 399 0.6 84 BULK-117d773e
22045 Bulk Product e45db831 Clothing $786.26 6 1.5 25 BULK-0fe00c6d
22046 Bulk Product 6f346d7c Clothing $668.80 209 4.6 73 BULK-1b8a2a0a
22047 Bulk Product 06655c31 Sports & Outdoors $261.51 395 4.4 95 BULK-8781478a
22048 Bulk Product 4f94d086 Sports & Outdoors $183.29 198 4.8 61 BULK-150df1f7
22049 Bulk Product 5fd4f0e2 Toys & Games $225.97 145 3.1 38 BULK-1d6c6bba
22050 Bulk Product 0a4b5f4e Sports & Outdoors $704.01 435 3.4 20 BULK-6967c915
22051 Bulk Product 2e5d833b Toys & Games $211.74 390 1.6 83 BULK-84e67d37
22052 Bulk Product f791f5cf Clothing $825.66 117 4.8 98 BULK-e4da2f13
22053 Bulk Product 08f07910 Toys & Games $63.47 294 1.1 3 BULK-61ef37be
22054 Bulk Product 06b0cd86 Electronics $666.62 338 2.7 81 BULK-2f2ce620
22055 Bulk Product 649e45b7 Electronics $564.93 329 4.5 18 BULK-181f22a7
22056 Bulk Product f3f97886 Electronics $53.83 19 1.1 77 BULK-10665ff1
22057 Bulk Product 128bc36f Sports & Outdoors $861.71 82 2.0 52 BULK-ff3a864e
22058 Bulk Product ab8bc88c Toys & Games $323.65 303 1.8 14 BULK-753c7cfd
22059 Bulk Product c3173fda Electronics $62.69 319 2.1 27 BULK-de6b4120
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