Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

44 ms

Page Size

25

Current Page

432 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 432 Results Showing 10776 - 10800 of 24441

ID Name Category Price Stock Rating Reviews SKU
11335 Bulk Product a3608393 Toys & Games $26.09 389 0.4 57 BULK-37a34287
11336 Bulk Product 51e803a1 Home & Garden $273.07 400 0.3 36 BULK-85dbfcb8
11337 Bulk Product 7f039952 Sports & Outdoors $333.74 79 3.6 36 BULK-2dbb9c5c
11338 Bulk Product 4ab0b182 Sports & Outdoors $374.29 14 1.1 50 BULK-1454cd28
11339 Bulk Product 9e2356cd Home & Garden $198.63 387 1.2 67 BULK-c42cfd16
11340 Bulk Product f71400b6 Books $831.03 403 1.4 96 BULK-1c1bb040
11341 Bulk Product 00ae3a89 Electronics $557.38 377 2.1 99 BULK-c063525c
11342 Bulk Product af46f991 Home & Garden $535.90 121 2.0 25 BULK-d7efe390
11343 Bulk Product 125f56f2 Sports & Outdoors $74.75 439 2.8 18 BULK-51c15d26
11344 Bulk Product 3bcc09d3 Sports & Outdoors $952.65 407 0.3 30 BULK-4d406802
11345 Bulk Product 8efdd125 Electronics $842.19 344 0.5 48 BULK-c208d299
11346 Bulk Product 4b2bbf53 Books $175.14 197 4.4 15 BULK-2d78c993
11347 Bulk Product 16ac082d Sports & Outdoors $474.64 81 1.8 53 BULK-83270fd5
11348 Bulk Product b52ea448 Toys & Games $415.39 220 3.7 74 BULK-73d8aacf
11349 Bulk Product 328608da Toys & Games $389.13 334 1.0 1 BULK-33a6c38d
11350 Bulk Product c902d36e Home & Garden $97.04 334 1.3 85 BULK-d59542b3
11351 Bulk Product 8b97f761 Sports & Outdoors $850.61 170 3.3 52 BULK-834cf0ee
11352 Bulk Product 232069cb Clothing $255.81 468 1.3 95 BULK-d2239152
11353 Bulk Product 3f37b070 Sports & Outdoors $75.65 275 3.4 46 BULK-042717b0
11354 Bulk Product beeb6cf8 Electronics $405.71 324 0.1 84 BULK-0c994e72
11355 Bulk Product 380d45c8 Sports & Outdoors $123.23 224 2.1 38 BULK-f3c5d413
11356 Bulk Product 50248473 Clothing $275.35 186 1.0 4 BULK-bf10fd4c
11357 Bulk Product ac078da4 Electronics $776.55 325 4.1 1 BULK-996c0cdc
11358 Bulk Product e93f5448 Books $921.22 393 4.1 90 BULK-022b28c1
11359 Bulk Product 57e0ddd6 Sports & Outdoors $10.36 431 0.2 71 BULK-7bc4ac8a
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