Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

44 ms

Page Size

25

Current Page

792 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 792 Results Showing 19776 - 19800 of 24441

ID Name Category Price Stock Rating Reviews SKU
20335 Bulk Product b768a43f Electronics $136.73 152 0.6 31 BULK-1d346cda
20336 Bulk Product f8a81286 Toys & Games $840.72 214 3.6 26 BULK-494a2572
20337 Bulk Product df4ca4d2 Sports & Outdoors $906.20 380 4.9 50 BULK-2ecd3f98
20338 Bulk Product 9d41f971 Home & Garden $457.27 479 3.9 5 BULK-876728f3
20339 Bulk Product 5671587f Home & Garden $958.57 44 0.7 62 BULK-1c310b87
20340 Bulk Product 3bddccdb Home & Garden $701.41 16 4.6 79 BULK-4e8a2ca8
20341 Bulk Product e991345a Toys & Games $536.49 145 4.3 82 BULK-0a288ace
20342 Bulk Product 965d717f Clothing $421.20 234 2.2 5 BULK-330ee3f0
20343 Bulk Product b756cfe8 Toys & Games $896.51 340 2.8 88 BULK-61978b79
20344 Bulk Product 41e28ac7 Electronics $592.87 89 3.3 4 BULK-cade3812
20345 Bulk Product 075548c2 Books $913.91 428 4.6 49 BULK-9da2ef31
20346 Bulk Product 1247f429 Books $885.58 459 1.6 34 BULK-e39d051f
20347 Bulk Product b92f78a0 Sports & Outdoors $123.09 391 2.4 40 BULK-ff890e96
20348 Bulk Product 64326e65 Books $336.61 402 4.3 88 BULK-a6303f22
20349 Bulk Product 1c679b92 Toys & Games $790.57 348 0.4 50 BULK-b6d22003
20350 Bulk Product 07179aee Clothing $268.69 450 0.8 41 BULK-50e59129
20351 Bulk Product d3313772 Sports & Outdoors $827.45 54 4.8 78 BULK-c7fd00c8
20352 Bulk Product 36a56e72 Home & Garden $424.43 324 2.6 85 BULK-d0f5e1fd
20353 Bulk Product 2d013650 Books $171.59 376 2.0 98 BULK-32dfa0b1
20354 Bulk Product c3f7ecd0 Home & Garden $649.44 194 4.2 67 BULK-e99627c7
20355 Bulk Product 576c0bc6 Toys & Games $542.38 184 4.2 78 BULK-d5ef730a
20356 Bulk Product 791fdbac Books $911.04 265 1.1 5 BULK-9b491aa2
20357 Bulk Product de01ab98 Home & Garden $81.48 133 2.4 84 BULK-b64d91a7
20358 Bulk Product 8108596c Sports & Outdoors $96.24 52 2.2 58 BULK-425e02a7
20359 Bulk Product 91a7cacc Clothing $606.52 450 2.5 2 BULK-7fb0b445
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