Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

30 ms

Page Size

50

Current Page

148 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 148 Results Showing 7351 - 7400 of 24441

ID Name Category Price Stock Rating Reviews SKU
7910 Bulk Product 208b2565 Home & Garden $767.61 44 1.9 52 BULK-683b35bd
7911 Bulk Product ee206296 Home & Garden $240.09 114 0.4 39 BULK-40b4e152
7912 Bulk Product e3eb0b2a Sports & Outdoors $440.58 442 0.5 97 BULK-31d7a944
7913 Bulk Product fd627db5 Books $820.35 35 4.6 69 BULK-5f47b5e1
7914 Bulk Product 91a8084e Clothing $1,008.36 375 2.1 24 BULK-f1a3282a
7915 Bulk Product 66e89c8c Toys & Games $636.52 265 4.6 46 BULK-6a9f9a94
7916 Bulk Product 59fa4f9a Clothing $620.59 171 3.6 46 BULK-02e4ec85
7917 Bulk Product a16e5fa7 Sports & Outdoors $854.48 445 1.2 23 BULK-c5d22f24
7918 Bulk Product e915bdfd Clothing $834.69 319 2.8 0 BULK-6e0df69c
7919 Bulk Product 46f155bb Books $753.42 437 0.9 49 BULK-bb7b94d6
7920 Bulk Product 3794c8ac Books $116.59 361 3.3 53 BULK-e41475c6
7921 Bulk Product 25eae69a Toys & Games $938.73 309 4.6 76 BULK-53a9bc1e
7922 Bulk Product 9d4f2325 Clothing $702.21 120 2.9 76 BULK-ad128918
7923 Bulk Product 4da8b5f8 Books $964.49 36 4.5 60 BULK-61b36adf
7924 Bulk Product 1c14ee47 Electronics $425.69 157 4.2 11 BULK-2e0cdc2c
7925 Bulk Product 56b9ddba Clothing $450.52 72 3.6 90 BULK-e9f34040
7926 Bulk Product 787cb4ac Home & Garden $884.10 243 1.9 8 BULK-cb2cc0a1
7927 Bulk Product 3bff9b3f Home & Garden $997.38 217 2.9 86 BULK-5ec9d4e7
7928 Bulk Product 11aecce0 Home & Garden $804.16 153 2.9 15 BULK-d3e57063
7929 Bulk Product edfb85b4 Toys & Games $101.41 175 0.6 45 BULK-91e6a396
7930 Bulk Product f79d89f7 Sports & Outdoors $967.10 313 3.8 30 BULK-798cfe84
7931 Bulk Product 1f32ea0d Electronics $764.36 411 0.9 91 BULK-8d6032c0
7932 Bulk Product 13734214 Sports & Outdoors $736.23 334 5.0 86 BULK-10d8b0b9
7933 Bulk Product 4058fd5f Clothing $75.67 20 3.0 11 BULK-1b145034
7934 Bulk Product c59bb4e0 Electronics $936.72 228 3.9 66 BULK-e2ad9a38
7935 Bulk Product 7c07c2c6 Clothing $298.24 183 2.2 58 BULK-7a964741
7936 Bulk Product 7a9b89ef Clothing $140.08 182 1.8 67 BULK-50187f4c
7937 Bulk Product 2e040337 Toys & Games $372.60 407 2.7 49 BULK-cb32c19e
7938 Bulk Product a91e4399 Books $828.55 427 2.7 75 BULK-f50f8064
7939 Bulk Product 7e8e60f5 Clothing $84.01 479 4.6 64 BULK-650bb786
7940 Bulk Product d7e8bd8c Sports & Outdoors $893.03 149 3.2 72 BULK-c88a361a
7941 Bulk Product 953b247a Sports & Outdoors $35.67 369 1.2 59 BULK-179286b6
7942 Bulk Product 51faca5c Books $487.23 117 4.3 39 BULK-13f19579
7943 Bulk Product 6ad25baa Clothing $25.88 350 0.1 69 BULK-72ded161
7944 Bulk Product 3c404350 Clothing $97.33 109 2.9 24 BULK-fa6608d4
7945 Bulk Product c8bf1994 Electronics $965.77 126 0.6 31 BULK-a4819196
7946 Bulk Product 1ed0b4cf Home & Garden $276.51 396 3.4 41 BULK-7506565d
7947 Bulk Product 2337cd75 Clothing $665.33 267 2.5 68 BULK-c0ced8cc
7948 Bulk Product ecd76ead Toys & Games $222.76 478 1.8 10 BULK-871c0965
7949 Bulk Product 91121033 Home & Garden $955.47 98 3.8 55 BULK-c1aff9d9
7950 Bulk Product 2c8d3633 Electronics $684.62 235 4.8 34 BULK-ee2342cd
7951 Bulk Product 9b3e5087 Electronics $79.03 461 0.2 63 BULK-2111d9b4
7952 Bulk Product 3559cde6 Sports & Outdoors $735.03 276 2.5 18 BULK-72bcb8ce
7953 Bulk Product 231d7c44 Electronics $916.00 208 3.3 51 BULK-4669314c
7954 Bulk Product ed4fa27b Clothing $683.99 134 2.2 2 BULK-f51e0fa7
7955 Bulk Product 6c5ef4de Toys & Games $466.58 346 1.6 21 BULK-875e3fcc
7956 Bulk Product ab746070 Home & Garden $566.63 324 0.5 92 BULK-199de726
7957 Bulk Product 365e465c Sports & Outdoors $115.72 58 3.8 48 BULK-4e88600c
7958 Bulk Product 28cbc48e Books $546.13 272 4.0 98 BULK-7fd1103b
7959 Bulk Product a2c19431 Books $817.00 275 1.0 37 BULK-76adc760
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