Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

856 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 856 Results Showing 21376 - 21400 of 24441

ID Name Category Price Stock Rating Reviews SKU
21935 Bulk Product f6847875 Toys & Games $138.27 432 4.2 88 BULK-859ef5f8
21936 Bulk Product b8f6482c Electronics $814.45 13 0.7 44 BULK-6df94678
21937 Bulk Product 80a9c83d Sports & Outdoors $39.16 286 2.6 40 BULK-903a659b
21938 Bulk Product 6523771f Books $922.83 108 2.1 32 BULK-c045f08b
21939 Bulk Product dbbd2962 Sports & Outdoors $615.38 452 0.1 67 BULK-0273eeba
21940 Bulk Product 7e791298 Home & Garden $627.54 215 4.8 35 BULK-e7238f18
21941 Bulk Product 65eb0b8d Clothing $405.55 389 4.4 14 BULK-fb7d4cf7
21942 Bulk Product 710cfdf5 Toys & Games $871.50 125 0.4 32 BULK-83280812
21943 Bulk Product f5918a4c Home & Garden $465.64 410 0.0 21 BULK-174b5146
21944 Bulk Product f6a78d21 Electronics $717.17 43 3.4 83 BULK-90fc48a2
21945 Bulk Product e647b380 Toys & Games $318.81 226 2.5 76 BULK-89ada1e0
21946 Bulk Product 9d658e3f Clothing $575.41 265 3.2 56 BULK-ec045e52
21947 Bulk Product 675a3700 Electronics $829.19 72 4.6 78 BULK-9ffcf69d
21948 Bulk Product 5b85c54c Clothing $491.61 50 3.8 19 BULK-bd241152
21949 Bulk Product a46f9053 Sports & Outdoors $613.96 322 3.9 5 BULK-c87b0ee1
21950 Bulk Product 5f82b64a Home & Garden $923.56 322 1.9 14 BULK-ed91db21
21951 Bulk Product c58e8af5 Clothing $740.67 106 2.6 40 BULK-895c6a10
21952 Bulk Product ae4166cd Toys & Games $463.43 460 3.3 77 BULK-609d5158
21953 Bulk Product ae8e5c9c Clothing $288.52 241 3.8 99 BULK-d35997a4
21954 Bulk Product 576a707d Toys & Games $739.66 360 4.7 33 BULK-728e2122
21955 Bulk Product 02de0b17 Home & Garden $570.82 444 1.0 13 BULK-b6c6c911
21956 Bulk Product 06b8ebb0 Toys & Games $94.51 275 0.7 14 BULK-c51e2de3
21957 Bulk Product 05d719db Books $703.41 396 4.3 64 BULK-7be05b83
21958 Bulk Product c3775751 Books $510.13 112 4.5 11 BULK-9dd4e5b5
21959 Bulk Product d2716ab6 Toys & Games $312.49 220 1.0 37 BULK-8811c598
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