Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

358 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 358 Results Showing 8926 - 8950 of 24441

ID Name Category Price Stock Rating Reviews SKU
9485 Bulk Product 9d53acb4 Home & Garden $996.53 315 1.4 26 BULK-5b40072d
9486 Bulk Product 4ff9e8e8 Electronics $890.58 266 2.3 34 BULK-e14a6527
9487 Bulk Product 78d1f11d Home & Garden $705.23 450 4.9 29 BULK-52904cb4
9488 Bulk Product f6537f2e Books $1,009.99 293 1.1 62 BULK-aae6f3ee
9489 Bulk Product 029d64b3 Books $925.67 291 0.4 19 BULK-ac0292d7
9490 Bulk Product a543e2fb Electronics $607.26 372 4.8 91 BULK-4914c60d
9491 Bulk Product aad81b47 Toys & Games $445.30 115 3.1 59 BULK-8ae1185b
9492 Bulk Product af4bc3e0 Home & Garden $580.18 116 4.8 80 BULK-249e6e59
9493 Bulk Product d649da81 Books $153.63 130 4.4 58 BULK-32431810
9494 Bulk Product e167d0f0 Home & Garden $446.37 152 0.5 27 BULK-ab13f981
9495 Bulk Product 4990027c Clothing $160.08 222 4.6 97 BULK-728c506c
9496 Bulk Product 80129666 Electronics $308.25 272 1.2 91 BULK-5a0b3309
9497 Bulk Product 87c13c48 Books $914.63 59 0.3 31 BULK-7dcb99c6
9498 Bulk Product 243c0d93 Sports & Outdoors $991.81 407 3.5 73 BULK-3147c7a9
9499 Bulk Product c32b9f4d Home & Garden $298.13 46 3.3 74 BULK-0d185160
9500 Bulk Product 95919a4f Books $874.70 337 5.0 75 BULK-855bb594
9501 Bulk Product fdf8509e Books $592.55 424 1.4 68 BULK-e54cec7f
9502 Bulk Product fc928c00 Electronics $305.04 51 4.8 51 BULK-2cdc8bd8
9503 Bulk Product 446b629a Sports & Outdoors $354.02 236 0.4 27 BULK-ef98f105
9504 Bulk Product 7477cbb8 Sports & Outdoors $541.86 386 2.1 99 BULK-b7d87b28
9505 Bulk Product a7f51c06 Electronics $331.63 432 4.9 70 BULK-33cff50e
9506 Bulk Product e8846008 Sports & Outdoors $255.37 2 1.6 73 BULK-66b4b6c8
9507 Bulk Product e39ea94b Electronics $994.70 16 4.8 61 BULK-25914218
9508 Bulk Product 1124b892 Sports & Outdoors $881.33 430 3.1 38 BULK-7d5ff139
9509 Bulk Product 3a52d0aa Clothing $33.58 356 2.7 38 BULK-1a9d456f
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