Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

278 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 278 Results Showing 6926 - 6950 of 24441

ID Name Category Price Stock Rating Reviews SKU
7485 Bulk Product 4ed764fa Home & Garden $159.67 305 2.6 40 BULK-2a0a9a9d
7486 Bulk Product a49c6c73 Sports & Outdoors $362.45 497 4.6 98 BULK-80d9a7ce
7487 Bulk Product 5c72b9d0 Books $259.38 461 1.2 42 BULK-bc640b38
7488 Bulk Product a8d67e16 Home & Garden $881.96 474 4.3 62 BULK-c3ad1c62
7489 Bulk Product 944117a4 Electronics $821.77 299 3.2 53 BULK-c0596e9c
7490 Bulk Product 7edfaa65 Toys & Games $484.40 445 3.9 70 BULK-1238ae68
7491 Bulk Product b17cdc72 Toys & Games $262.30 364 1.1 61 BULK-b999a7f9
7492 Bulk Product 5b5b584f Clothing $758.84 497 2.7 35 BULK-b4c783f1
7493 Bulk Product d0057a9c Toys & Games $429.92 70 2.1 69 BULK-c9bd8cb4
7494 Bulk Product 9cbf03f6 Sports & Outdoors $419.47 255 4.6 99 BULK-86f13574
7495 Bulk Product 537eef88 Home & Garden $520.47 175 3.2 22 BULK-f69cbe5b
7496 Bulk Product 0e691d65 Sports & Outdoors $527.31 88 3.9 92 BULK-54665a4d
7497 Bulk Product cd08cfbc Clothing $717.39 280 1.4 98 BULK-89313bb7
7498 Bulk Product 2c2ce88b Toys & Games $566.83 117 3.4 17 BULK-0c8cb8ba
7499 Bulk Product b2ea87af Toys & Games $290.50 207 1.0 9 BULK-058d2dd1
7500 Bulk Product a99c1e66 Books $832.38 470 3.1 41 BULK-64227756
7501 Bulk Product ca3245fa Toys & Games $609.20 281 4.6 67 BULK-08d7133d
7502 Bulk Product 76f9c821 Toys & Games $426.23 180 1.4 71 BULK-e9b43a91
7503 Bulk Product 88478251 Home & Garden $910.24 262 3.6 36 BULK-3fc17679
7504 Bulk Product 57138432 Toys & Games $640.72 298 4.2 75 BULK-c5e7ce36
7505 Bulk Product 05a043cd Clothing $763.09 66 3.5 46 BULK-656fbc02
7506 Bulk Product d44793ff Clothing $848.05 83 4.1 83 BULK-4875f556
7507 Bulk Product 15f231d3 Sports & Outdoors $578.49 2 1.6 22 BULK-07f8382d
7508 Bulk Product 7cc0c8f8 Toys & Games $397.20 72 3.0 72 BULK-69752389
7509 Bulk Product dd387f8a Toys & Games $431.23 67 3.4 46 BULK-a6f610f1
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