Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

893 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 893 Results Showing 22301 - 22325 of 24441

ID Name Category Price Stock Rating Reviews SKU
22860 Bulk Product 147b4821 Books $211.54 94 1.6 42 BULK-757d72bf
22861 Bulk Product 85991ef7 Electronics $683.11 274 3.6 44 BULK-3b70686f
22862 Bulk Product 38bfe46f Toys & Games $577.70 448 2.0 13 BULK-45b20bbc
22863 Bulk Product 59dea050 Home & Garden $767.40 157 3.8 12 BULK-36a070e4
22864 Bulk Product d5787862 Clothing $194.16 364 2.8 14 BULK-4782ebd8
22865 Bulk Product 47b55780 Sports & Outdoors $45.78 151 1.6 44 BULK-a0b88eb1
22866 Bulk Product 22f30d91 Home & Garden $628.70 24 1.2 56 BULK-03003b32
22867 Bulk Product 1c705c78 Clothing $920.81 378 2.1 96 BULK-87bdc1fc
22868 Bulk Product 9a4b6876 Toys & Games $60.83 175 2.5 49 BULK-fb9af2db
22869 Bulk Product e018665f Clothing $36.16 393 0.0 22 BULK-e26e2cd0
22870 Bulk Product 6a486a0f Toys & Games $953.59 309 1.4 34 BULK-329f0c35
22871 Bulk Product 20aca22d Electronics $553.75 303 0.6 17 BULK-5c247147
22872 Bulk Product 3e98d47a Home & Garden $480.52 459 1.3 49 BULK-dba0df2a
22873 Bulk Product 60478455 Clothing $816.58 145 3.1 53 BULK-b6579212
22874 Bulk Product 458baea8 Clothing $676.12 464 5.0 41 BULK-fc17399c
22875 Bulk Product 47653b93 Clothing $525.92 310 3.7 62 BULK-1dfb2a12
22876 Bulk Product f834430a Toys & Games $281.85 74 3.4 75 BULK-e6e219a4
22877 Bulk Product eb6797a6 Books $813.48 217 4.7 88 BULK-6d8b1f76
22878 Bulk Product 1206b7a9 Clothing $721.50 35 1.0 29 BULK-7a666c04
22879 Bulk Product 980eb4e4 Clothing $538.60 247 1.3 81 BULK-5dab4038
22880 Bulk Product 7469e375 Toys & Games $375.75 25 1.7 47 BULK-870dafd8
22881 Bulk Product 1d9e27f4 Toys & Games $251.08 60 0.4 41 BULK-f74c38d0
22882 Bulk Product 36ca45c2 Clothing $667.00 330 0.4 11 BULK-da8e4b60
22883 Bulk Product 72c1e54b Home & Garden $393.49 432 4.1 57 BULK-ee99c362
22884 Bulk Product d55e78a4 Books $165.85 136 2.0 48 BULK-114360d8
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