Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

977 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 977 Results Showing 24401 - 24425 of 24441

ID Name Category Price Stock Rating Reviews SKU
24960 Bulk Product 93d13490 Books $383.62 199 0.5 36 BULK-11f23144
24961 Bulk Product cb73bcb1 Home & Garden $743.91 463 1.0 94 BULK-3baf6525
24962 Bulk Product b0bfb1ad Books $43.43 322 2.1 5 BULK-0ba67e89
24963 Bulk Product a6333e8c Home & Garden $526.18 52 0.9 80 BULK-6db6f6de
24964 Bulk Product ec0d0d84 Toys & Games $599.72 362 3.6 55 BULK-078c88cf
24965 Bulk Product 3be09855 Clothing $434.39 100 1.0 33 BULK-a73492c9
24966 Bulk Product a566a5a5 Home & Garden $160.41 61 2.3 86 BULK-171b10a4
24967 Bulk Product d2162b8e Electronics $355.24 78 4.0 42 BULK-e9d46a4e
24968 Bulk Product c7d3a373 Clothing $89.57 176 1.0 3 BULK-eddfd6cb
24969 Bulk Product f5fb1151 Books $917.35 433 0.2 86 BULK-72b16fef
24970 Bulk Product 150ad134 Sports & Outdoors $772.83 469 0.1 1 BULK-d626984b
24971 Bulk Product 7969e091 Sports & Outdoors $133.97 198 1.8 54 BULK-86318924
24972 Bulk Product e612ca24 Clothing $466.38 384 2.9 95 BULK-9ffd2f2e
24973 Bulk Product b1f5c3d0 Toys & Games $504.35 221 2.9 76 BULK-e2c15073
24974 Bulk Product 0927b634 Toys & Games $401.05 313 0.6 96 BULK-d09d6080
24975 Bulk Product f02387e0 Clothing $979.43 16 3.6 56 BULK-bd3f633a
24976 Bulk Product 64bdb131 Home & Garden $909.42 187 1.4 2 BULK-2e3ef8af
24977 Bulk Product a69e3706 Sports & Outdoors $589.53 165 4.9 55 BULK-e7101567
24978 Bulk Product 37397e27 Toys & Games $169.93 323 1.3 23 BULK-79be089b
24979 Bulk Product 7d97f37b Clothing $228.48 177 5.0 41 BULK-3ac26009
24980 Bulk Product fb7e0e33 Books $199.62 256 3.0 31 BULK-f4413e52
24981 Bulk Product cc1470ba Books $112.26 279 0.9 24 BULK-9f939258
24982 Bulk Product 35d42b17 Clothing $188.61 127 4.3 24 BULK-fa0a462f
24983 Bulk Product 10283697 Clothing $538.73 490 4.8 39 BULK-99b0877b
24984 Bulk Product e0892413 Home & Garden $896.28 293 3.1 47 BULK-62dc8578
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