Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

50

Current Page

472 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 472 Results Showing 23551 - 23600 of 24441

ID Name Category Price Stock Rating Reviews SKU
24110 Bulk Product c4437b33 Books $452.34 459 4.0 76 BULK-a0651ce4
24111 Bulk Product 5fd02f65 Clothing $226.05 250 3.9 97 BULK-8f16bdb0
24112 Bulk Product 23b01236 Home & Garden $284.34 279 4.5 18 BULK-c15b0053
24113 Bulk Product dee28abb Electronics $60.14 350 0.8 22 BULK-5a4a02d4
24114 Bulk Product 43670b2e Toys & Games $410.04 204 3.5 41 BULK-ad3e756c
24115 Bulk Product 741c2d83 Books $948.92 28 0.5 0 BULK-8e4543fe
24116 Bulk Product 8340b493 Electronics $635.56 23 1.0 29 BULK-802e01af
24117 Bulk Product 3b282c46 Sports & Outdoors $651.41 376 4.1 69 BULK-6dc9be25
24118 Bulk Product 833afde8 Toys & Games $724.26 251 3.8 12 BULK-116c0f98
24119 Bulk Product de056a2a Sports & Outdoors $479.44 433 4.4 46 BULK-b8bf1768
24120 Bulk Product 89febfd3 Clothing $756.99 244 2.7 82 BULK-b46f76b1
24121 Bulk Product 054aecc3 Books $745.54 85 0.5 6 BULK-295022b5
24122 Bulk Product f4ae389f Books $284.87 495 4.6 5 BULK-c0280bfc
24123 Bulk Product 21a0ccf5 Electronics $431.86 23 2.6 32 BULK-3099db23
24124 Bulk Product abd5ed03 Toys & Games $384.13 133 0.4 87 BULK-d2398417
24125 Bulk Product c9437389 Toys & Games $674.90 351 4.4 46 BULK-709b825b
24126 Bulk Product 3173d292 Home & Garden $600.82 191 3.8 85 BULK-6cae01bf
24127 Bulk Product 2080d06c Sports & Outdoors $547.17 303 0.7 8 BULK-1477924d
24128 Bulk Product 281a49f0 Toys & Games $522.04 174 1.3 79 BULK-175a6376
24129 Bulk Product d71c4a9f Clothing $102.39 424 2.4 92 BULK-c4237eb1
24130 Bulk Product 30924a66 Clothing $335.08 396 4.2 58 BULK-a6b4ffb7
24131 Bulk Product c3f814c1 Clothing $935.86 277 2.1 0 BULK-ea4001ae
24132 Bulk Product d7fa3c55 Sports & Outdoors $160.56 15 0.5 61 BULK-46815570
24133 Bulk Product e39f6b03 Toys & Games $87.51 391 4.5 36 BULK-571be625
24134 Bulk Product bab8218a Electronics $860.81 223 2.8 43 BULK-5de95f2b
24135 Bulk Product 54563912 Toys & Games $72.85 275 4.0 95 BULK-96c05051
24136 Bulk Product e62e573e Electronics $840.03 242 4.0 32 BULK-0249959d
24137 Bulk Product 6218b968 Sports & Outdoors $614.92 351 0.6 7 BULK-177279bd
24138 Bulk Product 11068e81 Clothing $100.21 310 0.9 55 BULK-d8c726fb
24139 Bulk Product 8afa563b Toys & Games $304.13 282 2.7 49 BULK-ed01502e
24140 Bulk Product 5e466b3e Electronics $443.28 294 3.4 51 BULK-4f6f5c67
24141 Bulk Product dd4c9d0d Clothing $672.59 18 0.9 3 BULK-acf66e3b
24142 Bulk Product 4bedb915 Sports & Outdoors $589.07 307 4.7 71 BULK-aedab8e9
24143 Bulk Product 639d7fb9 Books $954.85 422 1.1 54 BULK-4d201366
24144 Bulk Product ece4f6ab Books $786.53 352 0.2 48 BULK-80f7e385
24145 Bulk Product 19a5a402 Toys & Games $148.29 92 3.0 51 BULK-46dcc005
24146 Bulk Product 4c79969f Electronics $884.31 52 3.6 11 BULK-ddfd98dc
24147 Bulk Product 0d4a1014 Electronics $106.51 397 1.4 11 BULK-85594fa3
24148 Bulk Product 12f83cd4 Toys & Games $22.70 75 0.0 19 BULK-4ec61b42
24149 Bulk Product f9d734dd Sports & Outdoors $234.41 36 0.6 69 BULK-26aabbab
24150 Bulk Product bdb72032 Clothing $719.45 125 4.2 8 BULK-de8859b1
24151 Bulk Product e5ca74a8 Electronics $373.15 463 3.9 75 BULK-b502be15
24152 Bulk Product 74507607 Sports & Outdoors $161.38 419 1.9 68 BULK-7613ac2e
24153 Bulk Product 8537836a Sports & Outdoors $949.61 21 1.1 69 BULK-b28b334f
24154 Bulk Product ee59fe38 Clothing $232.50 259 1.8 67 BULK-c389d4bf
24155 Bulk Product 1ea6fb2d Sports & Outdoors $168.28 316 4.5 76 BULK-ba3844ce
24156 Bulk Product 4fab751e Electronics $714.92 490 0.5 65 BULK-70f45d16
24157 Bulk Product 5681a0ef Toys & Games $190.46 110 3.9 0 BULK-25c4fa2d
24158 Bulk Product 00a89c7f Sports & Outdoors $915.97 44 0.2 3 BULK-76295047
24159 Bulk Product fbb7cc39 Electronics $250.69 185 4.3 50 BULK-d63cc160
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