Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

180 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 180 Results Showing 4476 - 4500 of 24441

ID Name Category Price Stock Rating Reviews SKU
5035 Bulk Product 4c172f33 Clothing $341.61 404 3.5 71 BULK-9504979b
5036 Bulk Product daa91d0d Sports & Outdoors $798.24 99 2.4 66 BULK-92a934bc
5037 Bulk Product e66ac441 Home & Garden $812.07 428 1.2 20 BULK-99f48a09
5038 Bulk Product e505190a Sports & Outdoors $268.60 210 1.6 44 BULK-28afb82f
5039 Bulk Product 5ba69550 Toys & Games $421.24 202 4.3 10 BULK-fca3f8dc
5040 Bulk Product fcbd5df7 Sports & Outdoors $152.60 378 3.1 33 BULK-3d71dd4a
5041 Bulk Product b5ecca18 Books $483.74 90 4.8 51 BULK-9750a48d
5042 Bulk Product 4cf57bd9 Toys & Games $858.27 337 2.7 52 BULK-b2947e2c
5043 Bulk Product 64045724 Clothing $675.86 338 3.5 16 BULK-b5a3bacd
5044 Bulk Product 5f39f5cf Electronics $138.90 431 0.2 3 BULK-165cc0a2
5045 Bulk Product 41a2b9d8 Toys & Games $134.10 427 3.0 95 BULK-209106b4
5046 Bulk Product bcddc950 Books $163.09 173 4.8 5 BULK-868c6fb8
5047 Bulk Product 0fbffd00 Toys & Games $118.29 487 2.8 40 BULK-10159b56
5048 Bulk Product f7429cdd Home & Garden $683.50 47 2.3 55 BULK-3603f305
5049 Bulk Product 1819f4b6 Electronics $674.99 174 1.6 75 BULK-5840cc11
5050 Bulk Product c083bd66 Home & Garden $58.07 206 1.6 47 BULK-31394bcf
5051 Bulk Product 8ccf0ef6 Toys & Games $202.23 193 0.1 16 BULK-b9ebd34b
5052 Bulk Product dcff48b1 Home & Garden $209.60 234 4.4 72 BULK-584af7ac
5053 Bulk Product 8cc32d6b Sports & Outdoors $670.03 360 0.1 8 BULK-150bdcb3
5054 Bulk Product 8a36c0b3 Clothing $377.72 47 3.8 1 BULK-382d7369
5055 Bulk Product cb970165 Home & Garden $969.06 141 4.5 74 BULK-10658a11
5056 Bulk Product 917435c0 Clothing $227.25 359 3.2 72 BULK-5f2485d3
5057 Bulk Product 9998653e Clothing $862.95 196 4.0 84 BULK-fce15b63
5058 Bulk Product 4bda1644 Home & Garden $297.16 425 1.2 40 BULK-a440991e
5059 Bulk Product fc6ade30 Electronics $550.52 309 2.3 43 BULK-56d799c6
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