Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

433 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 433 Results Showing 10801 - 10825 of 24441

ID Name Category Price Stock Rating Reviews SKU
11360 Bulk Product b11cd07a Toys & Games $142.61 401 2.0 30 BULK-c113ba88
11361 Bulk Product 4c227eda Toys & Games $845.17 195 2.1 69 BULK-c00ff232
11362 Bulk Product c880afc1 Home & Garden $912.09 334 2.5 95 BULK-4a62cb21
11363 Bulk Product 532b506f Clothing $307.15 94 3.1 15 BULK-8ac965f8
11364 Bulk Product 4667fa71 Sports & Outdoors $218.57 105 2.4 56 BULK-ddfb0cf3
11365 Bulk Product 5243bf9f Books $634.05 401 0.7 69 BULK-2e7adf5e
11366 Bulk Product 338cd35c Books $756.01 170 4.6 86 BULK-5ebbacd7
11367 Bulk Product d30b4349 Toys & Games $552.38 245 1.9 35 BULK-06eb8abb
11368 Bulk Product 89260b54 Electronics $155.60 141 0.5 37 BULK-bdd347e4
11369 Bulk Product 1eebdaaa Home & Garden $96.83 137 0.2 13 BULK-d56dd165
11370 Bulk Product 5985699e Books $475.60 295 0.9 91 BULK-08c79d8d
11371 Bulk Product df2100f7 Home & Garden $131.60 189 4.1 36 BULK-4c6462ef
11372 Bulk Product 7bc228a9 Books $836.69 89 0.4 93 BULK-4fe33818
11373 Bulk Product b84edd34 Clothing $873.91 295 4.3 19 BULK-2cf38275
11374 Bulk Product bf8985a2 Sports & Outdoors $726.20 8 2.9 3 BULK-f72cc189
11375 Bulk Product c92d94b6 Books $659.96 353 2.9 95 BULK-f359960e
11376 Bulk Product 375b0fff Clothing $292.68 484 2.3 91 BULK-62d8f718
11377 Bulk Product 2898aca3 Sports & Outdoors $385.95 133 0.4 85 BULK-2f17d3f7
11378 Bulk Product ec614f5d Electronics $826.91 191 3.1 50 BULK-b1c5f70c
11379 Bulk Product 26313e4a Toys & Games $835.05 64 1.3 29 BULK-c12afc82
11380 Bulk Product 207f6916 Electronics $24.60 45 2.2 54 BULK-01cba006
11381 Bulk Product 3f740e63 Toys & Games $851.58 466 2.0 6 BULK-dab143af
11382 Bulk Product 93a2b341 Books $792.81 138 2.5 95 BULK-fa2d6670
11383 Bulk Product 87a214d6 Sports & Outdoors $227.13 229 0.2 47 BULK-83b3e4fd
11384 Bulk Product 3501a5ed Books $74.69 478 2.0 86 BULK-ca3f2f7f
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