Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

509 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 509 Results Showing 12701 - 12725 of 24441

ID Name Category Price Stock Rating Reviews SKU
13260 Bulk Product edb656c1 Clothing $462.34 350 3.5 85 BULK-b001b8e9
13261 Bulk Product 8115b85e Books $687.32 321 4.4 0 BULK-57e2d72a
13262 Bulk Product 3c45fbf2 Sports & Outdoors $817.30 333 3.6 76 BULK-9d435853
13263 Bulk Product 81f07d74 Home & Garden $656.22 112 4.0 27 BULK-35320b37
13264 Bulk Product c7257ee1 Clothing $166.93 292 1.8 0 BULK-c5958005
13265 Bulk Product 385409e8 Home & Garden $260.72 288 4.8 41 BULK-05b28f1c
13266 Bulk Product a0ccc0a4 Books $912.08 219 4.4 16 BULK-b8c93450
13267 Bulk Product a1b554f9 Electronics $502.03 495 1.8 55 BULK-5e8c14df
13268 Bulk Product 57be9260 Books $719.87 233 0.4 21 BULK-af8b38c9
13269 Bulk Product 7884a3b1 Electronics $35.87 481 0.3 23 BULK-01f1e31f
13270 Bulk Product 502719be Clothing $205.30 252 3.9 79 BULK-0abc44d8
13271 Bulk Product 655688b1 Home & Garden $431.48 439 0.6 26 BULK-173d716a
13272 Bulk Product 71676be3 Clothing $576.82 470 4.3 15 BULK-bab59383
13273 Bulk Product dc9ed8ac Electronics $542.41 338 0.0 63 BULK-613aac37
13274 Bulk Product 7d405039 Home & Garden $357.35 414 1.3 92 BULK-e31b0672
13275 Bulk Product db1676f5 Electronics $526.58 216 1.4 60 BULK-807bd650
13276 Bulk Product 9ce1f4e0 Electronics $92.93 53 4.2 58 BULK-93681832
13277 Bulk Product d59ad54f Electronics $769.61 464 2.0 91 BULK-84f31254
13278 Bulk Product 52063a6e Clothing $69.10 333 0.3 96 BULK-de1418f1
13279 Bulk Product d6c5bb0d Sports & Outdoors $318.59 159 3.6 22 BULK-d6216df1
13280 Bulk Product 08049102 Electronics $89.20 396 3.9 85 BULK-2a5ab8b2
13281 Bulk Product 8ebc579b Sports & Outdoors $762.37 41 1.9 18 BULK-7957ecca
13282 Bulk Product e0d46179 Clothing $123.99 74 0.3 91 BULK-36880e76
13283 Bulk Product ec93677f Home & Garden $271.02 354 0.9 7 BULK-7674efe5
13284 Bulk Product 6656a1f0 Sports & Outdoors $926.27 322 4.4 52 BULK-4525c446
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