Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

530 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 530 Results Showing 13226 - 13250 of 24441

ID Name Category Price Stock Rating Reviews SKU
13785 Bulk Product bc2c03db Electronics $346.77 49 1.2 72 BULK-f69c0978
13786 Bulk Product 72b01186 Clothing $410.84 29 4.7 97 BULK-514433fc
13787 Bulk Product 76fc4f4b Sports & Outdoors $140.05 296 2.0 16 BULK-17522861
13788 Bulk Product f7b6cf1c Books $686.26 222 2.1 38 BULK-11a874e3
13789 Bulk Product 7fb2e9f9 Clothing $941.30 296 2.1 1 BULK-8c309f5f
13790 Bulk Product b6781efc Home & Garden $510.80 32 3.2 9 BULK-cba7017f
13791 Bulk Product 21d8f596 Home & Garden $488.98 155 3.9 68 BULK-27ab27f1
13792 Bulk Product af8a7f7a Clothing $915.93 186 3.4 19 BULK-626dee72
13793 Bulk Product 53b76db9 Electronics $724.83 102 1.8 23 BULK-d106a16f
13794 Bulk Product d4f5e751 Home & Garden $621.46 168 5.0 55 BULK-8ca8487e
13795 Bulk Product 9d0af0cc Clothing $278.67 300 4.4 54 BULK-0a96bc65
13796 Bulk Product 4ad5cb21 Electronics $655.41 356 1.8 36 BULK-be5b7141
13797 Bulk Product 0bd49f69 Electronics $658.73 391 3.4 78 BULK-b0e08f61
13798 Bulk Product 249c44a9 Electronics $863.46 430 1.7 33 BULK-062918a4
13799 Bulk Product 7ea8fec2 Home & Garden $720.12 148 1.9 82 BULK-114f70d0
13800 Bulk Product 0aaee706 Books $881.58 78 2.3 51 BULK-d7b62788
13801 Bulk Product 7cf03bac Books $264.32 387 4.7 37 BULK-9167c985
13802 Bulk Product eaefdb48 Clothing $909.55 148 3.1 1 BULK-64643f9d
13803 Bulk Product 788d8f27 Clothing $430.69 489 2.4 4 BULK-5c80b688
13804 Bulk Product e6dbfc61 Clothing $292.62 424 3.7 98 BULK-245cd77b
13805 Bulk Product 347046bd Clothing $62.60 402 4.6 62 BULK-ba6a249c
13806 Bulk Product 5a098e66 Books $58.19 236 3.6 70 BULK-97d07b11
13807 Bulk Product e41e8cb2 Electronics $33.62 349 4.0 35 BULK-fce3f548
13808 Bulk Product c87ce070 Electronics $649.77 242 1.5 22 BULK-659ce4b0
13809 Bulk Product fab3ff86 Sports & Outdoors $501.51 408 0.4 84 BULK-bcfab258
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