Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

49 ms

Page Size

25

Current Page

742 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 742 Results Showing 18526 - 18550 of 24441

ID Name Category Price Stock Rating Reviews SKU
19085 Bulk Product c6f55d8b Toys & Games $30.73 463 0.9 27 BULK-21dc6e9a
19086 Bulk Product b786b913 Electronics $419.79 377 1.9 72 BULK-ec1f5fe0
19087 Bulk Product e757c605 Toys & Games $509.25 244 0.1 90 BULK-2a896f55
19088 Bulk Product dde20d82 Electronics $563.44 246 2.1 22 BULK-0cac0952
19089 Bulk Product cddd1dbf Toys & Games $681.30 175 3.9 25 BULK-6159c860
19090 Bulk Product 827b2cf6 Electronics $766.53 476 2.1 20 BULK-acc234a5
19091 Bulk Product 9b800595 Home & Garden $311.70 253 1.3 57 BULK-73ba89be
19092 Bulk Product dadcb971 Home & Garden $779.94 7 3.1 4 BULK-fe32fdf9
19093 Bulk Product abc4c77d Home & Garden $369.78 439 2.3 36 BULK-e5e6cbe7
19094 Bulk Product 88bb3cf7 Home & Garden $432.32 476 1.4 58 BULK-5706d96f
19095 Bulk Product d77ba7c4 Sports & Outdoors $851.99 436 0.5 16 BULK-b0361958
19096 Bulk Product 20703f68 Home & Garden $907.19 367 3.6 44 BULK-d3c75741
19097 Bulk Product f496c628 Toys & Games $363.14 213 4.4 46 BULK-1ae2c59f
19098 Bulk Product dcba4ce4 Electronics $946.68 317 2.4 59 BULK-b5ac7214
19099 Bulk Product 7061d9a7 Books $254.51 311 0.6 16 BULK-a6d8f2ae
19100 Bulk Product ad9beb9c Home & Garden $514.41 426 3.0 24 BULK-1188e9d1
19101 Bulk Product f1ff4c6e Books $519.45 107 3.3 41 BULK-a6d5904c
19102 Bulk Product 5a8ad763 Toys & Games $945.25 100 4.6 21 BULK-e4178f74
19103 Bulk Product c118f861 Home & Garden $996.92 128 4.2 3 BULK-66d92c9a
19104 Bulk Product 86db11c1 Toys & Games $167.92 89 1.0 47 BULK-dfb7d361
19105 Bulk Product d1a79644 Electronics $413.58 123 1.3 9 BULK-e866de3e
19106 Bulk Product 216cc792 Books $976.11 73 2.7 64 BULK-79ac26ce
19107 Bulk Product fd9cf4d8 Toys & Games $254.07 201 2.6 44 BULK-1bcbf9b3
19108 Bulk Product 26da4ec5 Books $93.46 230 2.4 96 BULK-f4cab0e0
19109 Bulk Product 7b22bc72 Clothing $689.43 32 3.4 1 BULK-dc849777
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