Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

42 ms

Page Size

50

Current Page

168 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 168 Results Showing 8351 - 8400 of 24441

ID Name Category Price Stock Rating Reviews SKU
8910 Bulk Product e6c1fdb1 Clothing $427.15 384 2.6 12 BULK-4c065270
8911 Bulk Product 844be354 Books $449.57 126 0.5 94 BULK-15abebe0
8912 Bulk Product d4685d6b Sports & Outdoors $206.21 82 0.0 52 BULK-032ace8e
8913 Bulk Product d8de8b70 Toys & Games $99.27 437 2.9 43 BULK-53e86864
8914 Bulk Product a6112280 Toys & Games $518.32 323 0.8 48 BULK-6217f4e8
8915 Bulk Product 2cb5e323 Books $561.06 456 3.3 84 BULK-93f30df7
8916 Bulk Product 53dae5c6 Toys & Games $1,006.21 184 2.1 8 BULK-5e9f7a25
8917 Bulk Product 43a6d9f4 Books $394.53 53 2.4 13 BULK-df5fabdf
8918 Bulk Product 6c4b32a6 Books $295.49 419 2.8 35 BULK-7cff1a3c
8919 Bulk Product e190adc1 Sports & Outdoors $861.67 227 4.5 73 BULK-a0230a17
8920 Bulk Product 7fa79841 Books $666.60 84 1.4 36 BULK-d1c6ff7c
8921 Bulk Product 0b673c5c Home & Garden $942.62 26 5.0 8 BULK-6ec5389a
8922 Bulk Product cf79b256 Sports & Outdoors $918.05 297 3.6 10 BULK-296b5c32
8923 Bulk Product 9d6a064f Electronics $836.84 439 2.2 0 BULK-5f1f250f
8924 Bulk Product a22b421b Books $684.82 419 2.4 31 BULK-f6510439
8925 Bulk Product 6cdc5a94 Books $894.70 270 2.7 59 BULK-42c6bcdf
8926 Bulk Product 81b03fe5 Clothing $241.98 5 4.9 84 BULK-ddd31125
8927 Bulk Product d0b22834 Home & Garden $443.33 372 5.0 34 BULK-841ecc77
8928 Bulk Product 49c24a97 Clothing $184.08 246 4.7 10 BULK-6b823aca
8929 Bulk Product bdc10c3b Books $847.81 360 0.2 1 BULK-e3f255ac
8930 Bulk Product 7f254705 Home & Garden $681.47 243 0.6 44 BULK-670f2808
8931 Bulk Product 6f2f70df Clothing $362.31 378 1.0 51 BULK-8539ec95
8932 Bulk Product 85f1182f Clothing $683.12 93 4.4 25 BULK-27e95365
8933 Bulk Product f8ef2a11 Clothing $232.85 370 2.9 8 BULK-af4efed3
8934 Bulk Product a7a4e60e Electronics $431.46 411 1.6 19 BULK-c047a7e8
8935 Bulk Product 70627606 Electronics $20.03 255 1.0 22 BULK-4a29fcb9
8936 Bulk Product 82c77d0f Sports & Outdoors $41.38 189 0.0 49 BULK-f2526fb9
8937 Bulk Product 2954f6ff Books $358.82 165 3.2 94 BULK-564241ae
8938 Bulk Product d6cfab39 Electronics $848.39 112 0.2 78 BULK-5e2dd8dd
8939 Bulk Product cbf35bb8 Electronics $336.69 211 4.8 97 BULK-5b764076
8940 Bulk Product c5ecc782 Clothing $397.39 135 0.4 87 BULK-362ca206
8941 Bulk Product 287a191e Sports & Outdoors $219.96 131 3.9 72 BULK-2cb19e11
8942 Bulk Product cab75f87 Books $672.66 247 4.5 58 BULK-98d7c8c4
8943 Bulk Product fef36f06 Sports & Outdoors $1,000.06 295 2.8 4 BULK-5d17ae20
8944 Bulk Product 79dcd7f5 Electronics $459.14 473 0.9 75 BULK-6cc3b2f4
8945 Bulk Product cd81a7e6 Sports & Outdoors $360.37 217 3.3 96 BULK-f2d33a00
8946 Bulk Product 36de0714 Clothing $746.96 229 0.7 51 BULK-2b048d21
8947 Bulk Product d980ac4b Toys & Games $334.91 234 3.5 7 BULK-849c6743
8948 Bulk Product 79048073 Clothing $700.32 362 3.3 59 BULK-1ad304b6
8949 Bulk Product daf8118f Home & Garden $602.44 83 4.1 49 BULK-9d04563e
8950 Bulk Product 440fd013 Home & Garden $820.36 192 4.4 5 BULK-d9ae5078
8951 Bulk Product 5180029b Home & Garden $926.17 297 4.7 15 BULK-e9424580
8952 Bulk Product 130c0e82 Books $383.86 315 0.1 96 BULK-46c3422b
8953 Bulk Product 3f9a1811 Clothing $354.03 129 2.1 41 BULK-73dcd0f2
8954 Bulk Product 0ec4716c Clothing $763.78 277 4.2 10 BULK-2c950cc8
8955 Bulk Product 067b9d2e Books $895.05 275 2.5 0 BULK-4248f812
8956 Bulk Product 06831358 Toys & Games $220.05 498 0.0 85 BULK-d82c0a50
8957 Bulk Product 3c92621e Electronics $339.81 89 2.8 76 BULK-6738b70a
8958 Bulk Product 6c9c9f29 Toys & Games $36.70 134 4.3 37 BULK-73028e26
8959 Bulk Product 09b74ff2 Clothing $755.09 247 2.2 27 BULK-cae87a02
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