Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

50

Current Page

447 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 447 Results Showing 22301 - 22350 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
22885 Bulk Product 13a7f271 Clothing $360.36 311 4.4 43 BULK-62adb7d5
22886 Bulk Product f9b9e622 Clothing $742.01 499 1.4 95 BULK-ecdfda02
22887 Bulk Product 50a5b2f9 Clothing $446.65 154 2.2 45 BULK-1768d4e0
22888 Bulk Product 1c02dbd8 Electronics $154.13 379 0.0 78 BULK-7c16d619
22889 Bulk Product feb2f8af Home & Garden $795.00 464 3.1 98 BULK-a9c8dabf
22890 Bulk Product e37400b9 Electronics $593.69 228 3.2 87 BULK-ee26d5fd
22891 Bulk Product c944aa8d Sports & Outdoors $281.83 6 0.7 23 BULK-34d0fb72
22892 Bulk Product 82f88c09 Sports & Outdoors $845.80 79 3.2 28 BULK-ea5dbac1
22893 Bulk Product 761a6223 Sports & Outdoors $485.07 4 3.7 6 BULK-d7b1827b
22894 Bulk Product cb157c4a Sports & Outdoors $836.40 354 2.6 37 BULK-11cd78f9
22895 Bulk Product ba80a0e0 Books $529.62 25 1.7 76 BULK-91bebc7d
22896 Bulk Product 6ed00e45 Home & Garden $735.71 371 2.4 44 BULK-269ed5c0
22897 Bulk Product ba81e032 Electronics $105.64 493 0.3 26 BULK-5c4f9483
22898 Bulk Product d75799ad Toys & Games $799.46 343 3.4 66 BULK-2b18da8d
22899 Bulk Product fe62c649 Electronics $474.56 283 1.5 45 BULK-b8a8ec4d
22900 Bulk Product 33026166 Sports & Outdoors $848.70 268 0.9 32 BULK-079df7ac
22901 Bulk Product 144131c0 Sports & Outdoors $901.47 331 2.3 31 BULK-954c79ba
22902 Bulk Product 87ff5ec6 Home & Garden $350.35 488 2.8 92 BULK-91b7f2dd
22903 Bulk Product 0486ace7 Clothing $578.90 461 0.9 93 BULK-aaf8b09a
22904 Bulk Product 77835a24 Clothing $1,008.14 216 1.4 65 BULK-6508e808
22905 Bulk Product c0231bb1 Electronics $720.08 461 0.2 84 BULK-595ab9ae
22906 Bulk Product 7c8b6847 Clothing $363.38 211 1.4 35 BULK-c37bf582
22907 Bulk Product 5bf376f3 Toys & Games $89.55 445 2.8 20 BULK-29b4cdbd
22908 Bulk Product d715941e Clothing $681.97 3 0.7 8 BULK-73860007
22909 Bulk Product 5f1e5bd0 Clothing $970.58 72 4.7 58 BULK-8b934b53
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