Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

309 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 309 Results Showing 7701 - 7725 of 24441

ID Name Category Price Stock Rating Reviews SKU
8260 Bulk Product 20d84499 Toys & Games $747.00 349 2.2 28 BULK-ee0e7323
8261 Bulk Product 15d9d5a4 Books $375.37 110 2.3 32 BULK-378e0aef
8262 Bulk Product 80c37ae0 Toys & Games $464.14 79 4.8 19 BULK-e110a315
8263 Bulk Product 536e8309 Electronics $858.73 114 1.7 19 BULK-57ba8b44
8264 Bulk Product 3d323a88 Books $206.09 87 2.0 19 BULK-48cc4820
8265 Bulk Product b4893ee9 Clothing $876.86 155 4.0 14 BULK-8c232f75
8266 Bulk Product 4f703ec2 Toys & Games $439.30 405 1.9 18 BULK-f878c4ca
8267 Bulk Product 046672a0 Toys & Games $27.92 464 1.1 91 BULK-6eaf8ec7
8268 Bulk Product 4623ae78 Sports & Outdoors $699.62 421 1.4 10 BULK-5b4ee052
8269 Bulk Product 83824dda Books $112.01 244 1.9 98 BULK-f0316415
8270 Bulk Product 7a7f082d Toys & Games $196.36 114 1.9 53 BULK-6c085fe5
8271 Bulk Product c1a83681 Home & Garden $305.85 72 1.0 11 BULK-61ca213a
8272 Bulk Product 18f7f6c1 Toys & Games $399.40 73 2.2 86 BULK-0a68c939
8273 Bulk Product 031294d3 Clothing $72.00 186 2.1 81 BULK-14dd40a1
8274 Bulk Product 982d07b9 Books $49.41 330 0.7 74 BULK-d3992fef
8275 Bulk Product 321ee55c Toys & Games $464.07 332 4.3 34 BULK-bc8239ec
8276 Bulk Product 5add8a93 Sports & Outdoors $226.30 61 0.9 55 BULK-d3f11f16
8277 Bulk Product 066d84fd Clothing $598.79 359 0.5 24 BULK-2c4eacf8
8278 Bulk Product c231607c Electronics $463.09 451 1.6 22 BULK-e0cb8000
8279 Bulk Product c7e9bdc6 Clothing $198.52 163 3.5 45 BULK-75a33be2
8280 Bulk Product ef46dae0 Home & Garden $547.59 302 4.9 56 BULK-b3da6b5c
8281 Bulk Product 3e28d2e1 Books $959.01 186 4.9 80 BULK-6a3abd01
8282 Bulk Product c0423e9c Home & Garden $336.76 217 1.9 28 BULK-7f69cb0b
8283 Bulk Product 244da6c3 Toys & Games $25.80 464 1.7 23 BULK-77b16e1c
8284 Bulk Product 17fc9df7 Sports & Outdoors $384.23 65 0.1 44 BULK-8e15fd97
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