Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

234 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 234 Results Showing 5826 - 5850 of 24441

ID Name Category Price Stock Rating Reviews SKU
6385 Bulk Product 8e913841 Toys & Games $186.35 356 4.8 67 BULK-59d735bd
6386 Bulk Product fcdedca2 Home & Garden $937.92 51 0.8 72 BULK-bfba7bf6
6387 Bulk Product defe85b9 Toys & Games $758.11 431 1.4 51 BULK-92c1b122
6388 Bulk Product 1ef4766f Electronics $660.02 126 4.0 48 BULK-2306614f
6389 Bulk Product f795ac26 Toys & Games $834.70 365 4.4 4 BULK-0b55cdf0
6390 Bulk Product ddddac30 Clothing $591.82 343 2.2 45 BULK-66ca4a19
6391 Bulk Product 562923e1 Books $190.86 329 4.4 19 BULK-1b46d9bc
6392 Bulk Product 3b78d24b Clothing $817.39 320 1.3 28 BULK-09e9aa38
6393 Bulk Product 0b50eb8b Sports & Outdoors $333.61 422 0.1 23 BULK-58fefda6
6394 Bulk Product ff817a02 Home & Garden $786.56 163 2.6 6 BULK-75b432d3
6395 Bulk Product ad155264 Home & Garden $58.04 110 4.9 79 BULK-c4d8096a
6396 Bulk Product ac6bb655 Home & Garden $798.09 119 1.8 20 BULK-e0e7fb06
6397 Bulk Product cb26aac3 Electronics $572.77 87 2.6 92 BULK-66cad410
6398 Bulk Product da089472 Toys & Games $659.80 139 2.4 79 BULK-42e03af2
6399 Bulk Product 1d95c134 Books $238.92 264 1.5 64 BULK-3aef4ecb
6400 Bulk Product b124c4cc Books $863.86 402 1.9 67 BULK-3e6ddb48
6401 Bulk Product 0609d24a Home & Garden $587.58 412 4.7 6 BULK-e95b927d
6402 Bulk Product 12a4ffeb Toys & Games $476.02 208 0.3 51 BULK-5b9edd72
6403 Bulk Product 499daecd Toys & Games $45.53 279 1.0 38 BULK-ae60e98c
6404 Bulk Product beea7b9f Home & Garden $691.50 65 2.5 86 BULK-4733108d
6405 Bulk Product befb5b2e Toys & Games $394.23 146 1.4 27 BULK-61e30b25
6406 Bulk Product 39808c31 Books $978.24 335 3.8 52 BULK-408ec9ee
6407 Bulk Product 66729242 Home & Garden $725.64 435 0.0 19 BULK-d73f0aa4
6408 Bulk Product bb333760 Toys & Games $308.64 242 1.0 91 BULK-46b03187
6409 Bulk Product e2d4e6b1 Home & Garden $30.89 85 0.7 10 BULK-b10449df
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