Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

50

Current Page

243 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 243 Results Showing 12101 - 12150 of 24441

ID Name Category Price Stock Rating Reviews SKU
12660 Bulk Product 62a2a688 Clothing $561.85 110 0.6 33 BULK-8aab2c42
12661 Bulk Product e684fa3d Clothing $410.95 213 4.0 32 BULK-7e322318
12662 Bulk Product e9b7a7ce Home & Garden $662.25 411 4.5 61 BULK-8317c2d8
12663 Bulk Product 0366b8b1 Home & Garden $685.66 495 3.4 25 BULK-55257321
12664 Bulk Product eddd470a Home & Garden $710.59 264 2.5 43 BULK-06696538
12665 Bulk Product 54d2a653 Sports & Outdoors $161.49 192 4.4 57 BULK-85dd29c1
12666 Bulk Product 44ecad23 Toys & Games $862.15 139 1.4 85 BULK-6c3c5fd7
12667 Bulk Product 4c6d61f2 Electronics $707.84 170 1.7 78 BULK-bd40b791
12668 Bulk Product 03447bb1 Books $209.31 440 3.0 69 BULK-37d252fa
12669 Bulk Product f20ec70f Electronics $424.20 423 1.1 34 BULK-c1502f10
12670 Bulk Product c5be997d Clothing $160.71 254 0.5 81 BULK-9aa70d75
12671 Bulk Product 6781c3c8 Home & Garden $688.56 309 2.8 37 BULK-104aec82
12672 Bulk Product 2291571c Toys & Games $164.26 318 1.6 14 BULK-af46ed51
12673 Bulk Product 0c74a06f Sports & Outdoors $532.03 165 1.7 41 BULK-99e015d8
12674 Bulk Product 5dd425ab Electronics $289.04 238 0.6 50 BULK-3b19b16d
12675 Bulk Product 69e7aa0e Electronics $335.15 368 0.2 93 BULK-adaaa3b5
12676 Bulk Product b3f8cff1 Sports & Outdoors $637.40 434 0.4 38 BULK-99fac0fb
12677 Bulk Product 67d73611 Home & Garden $938.67 198 2.3 79 BULK-3781a31a
12678 Bulk Product 10fd6ada Sports & Outdoors $674.41 361 1.0 19 BULK-37622826
12679 Bulk Product 4d7e6c86 Toys & Games $264.43 450 2.8 18 BULK-0dbf513f
12680 Bulk Product b91124c3 Sports & Outdoors $296.79 285 2.6 31 BULK-e7279c7e
12681 Bulk Product ca2b5015 Sports & Outdoors $103.95 280 2.2 26 BULK-2005ee33
12682 Bulk Product f27e2962 Toys & Games $70.73 212 2.0 69 BULK-402f385b
12683 Bulk Product facd8069 Home & Garden $130.50 232 2.5 19 BULK-b07c53a6
12684 Bulk Product 6d32448f Books $291.32 327 3.0 96 BULK-cd38f787
12685 Bulk Product c4aa8ef9 Toys & Games $942.54 417 0.7 5 BULK-82218064
12686 Bulk Product eb402f3c Books $657.06 495 2.9 52 BULK-d714675f
12687 Bulk Product b2ace0d1 Clothing $398.16 254 2.0 58 BULK-f994e0c5
12688 Bulk Product d10e3d43 Clothing $303.71 185 2.3 50 BULK-3fd76008
12689 Bulk Product 100a06db Clothing $715.69 79 1.8 43 BULK-e86d4cf6
12690 Bulk Product c83beddc Books $372.57 347 1.6 0 BULK-3c73edcb
12691 Bulk Product 307f5c13 Toys & Games $761.65 388 4.6 66 BULK-9e4663a7
12692 Bulk Product 5869c4a6 Electronics $528.09 315 2.1 56 BULK-cfca55d9
12693 Bulk Product eea432a3 Electronics $232.82 355 0.9 82 BULK-8d2fc5c0
12694 Bulk Product 7e17241c Clothing $173.06 465 2.2 74 BULK-f2d98098
12695 Bulk Product 3ae9cdfd Clothing $562.74 195 3.1 24 BULK-eb0f06f9
12696 Bulk Product ead94c90 Toys & Games $928.01 276 1.8 13 BULK-5c7758b9
12697 Bulk Product 6bc8f1b3 Books $362.04 290 4.5 66 BULK-47751b8a
12698 Bulk Product bdc80887 Sports & Outdoors $913.21 250 4.6 10 BULK-9755401a
12699 Bulk Product 98e01feb Books $422.85 293 1.3 48 BULK-2540bfee
12700 Bulk Product e82a5ae5 Clothing $330.68 432 1.4 5 BULK-d1ce0dc5
12701 Bulk Product e9f07e1c Toys & Games $860.54 151 2.9 61 BULK-16104628
12702 Bulk Product ea56cb3a Home & Garden $500.00 52 4.9 34 BULK-3e0bbb1f
12703 Bulk Product fdf7f698 Books $212.81 54 3.4 3 BULK-29da68d6
12704 Bulk Product fcc5220e Toys & Games $852.84 269 4.9 53 BULK-fd68e348
12705 Bulk Product 50df22ed Sports & Outdoors $235.87 61 4.0 41 BULK-8dd0673d
12706 Bulk Product ac3b9d88 Sports & Outdoors $316.24 457 2.8 90 BULK-faeb0149
12707 Bulk Product fbec67b1 Books $895.55 254 1.0 52 BULK-141b3636
12708 Bulk Product eabac6cd Home & Garden $527.75 65 0.9 1 BULK-70f41987
12709 Bulk Product e8a4f809 Sports & Outdoors $244.11 443 2.9 24 BULK-6cd51e0a
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