Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

345 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 345 Results Showing 8601 - 8625 of 24441

ID Name Category Price Stock Rating Reviews SKU
9160 Bulk Product 73674b81 Books $81.74 340 0.2 0 BULK-39606520
9161 Bulk Product 8d0a327e Home & Garden $793.60 423 3.0 58 BULK-b6702215
9162 Bulk Product ee897684 Toys & Games $87.12 47 3.8 68 BULK-b75102ab
9163 Bulk Product a7271979 Electronics $395.06 336 4.1 4 BULK-b0c517e6
9164 Bulk Product 7b61ee43 Electronics $674.88 101 1.1 97 BULK-228e7842
9165 Bulk Product 4d0ceee8 Clothing $73.21 172 3.2 48 BULK-5ced5c0e
9166 Bulk Product ee456149 Sports & Outdoors $461.60 486 0.5 4 BULK-8da1779b
9167 Bulk Product e3b67a47 Sports & Outdoors $181.11 190 1.3 58 BULK-cda5f263
9168 Bulk Product b6c2add5 Toys & Games $262.78 43 3.6 30 BULK-30aeb9ae
9169 Bulk Product 627e5a35 Clothing $12.40 129 3.0 53 BULK-d6a629ba
9170 Bulk Product 0e5e8645 Clothing $102.63 12 2.2 58 BULK-ee6db7b6
9171 Bulk Product dc3507e6 Toys & Games $809.42 401 3.4 38 BULK-48651081
9172 Bulk Product b1f2809d Clothing $740.23 309 4.2 62 BULK-a0feba5e
9173 Bulk Product 135bd966 Clothing $862.86 30 3.5 8 BULK-8a095f1a
9174 Bulk Product 0111ee5b Electronics $364.37 104 0.1 84 BULK-3882b7e2
9175 Bulk Product 620cb7a2 Toys & Games $351.71 172 3.9 2 BULK-60cfbfb2
9176 Bulk Product 248edf4e Toys & Games $281.27 62 0.6 19 BULK-f0c840d5
9177 Bulk Product 4eeacba6 Home & Garden $824.08 313 3.2 93 BULK-d672d9e1
9178 Bulk Product 33751151 Home & Garden $707.63 96 4.1 60 BULK-e3c07347
9179 Bulk Product 977e17af Clothing $961.43 402 3.3 61 BULK-937ac35f
9180 Bulk Product 9fe1f071 Books $19.59 263 3.5 76 BULK-083d9494
9181 Bulk Product cc3a4ba7 Home & Garden $347.72 308 3.0 14 BULK-1907a69a
9182 Bulk Product ca8bd018 Clothing $909.06 161 0.6 13 BULK-b0c0d41a
9183 Bulk Product 3e6918ac Home & Garden $890.57 349 0.0 85 BULK-a208d8ce
9184 Bulk Product 0faf245c Sports & Outdoors $474.13 132 1.1 82 BULK-41324223
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