Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

346 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 346 Results Showing 8626 - 8650 of 24441

ID Name Category Price Stock Rating Reviews SKU
9185 Bulk Product 44f4a688 Home & Garden $512.21 126 2.1 90 BULK-36f60dc7
9186 Bulk Product c05c1963 Sports & Outdoors $792.18 351 1.0 37 BULK-39ad5ab7
9187 Bulk Product 61ed88be Sports & Outdoors $641.93 93 4.3 11 BULK-3957e69b
9188 Bulk Product ff99457c Sports & Outdoors $21.88 376 4.6 23 BULK-7b45e833
9189 Bulk Product 861a4960 Clothing $80.89 287 4.9 76 BULK-8233201b
9190 Bulk Product 0496777a Clothing $259.43 498 0.1 73 BULK-6b048156
9191 Bulk Product 1cfb4197 Sports & Outdoors $711.62 144 0.2 93 BULK-5b195262
9192 Bulk Product 92933ad5 Home & Garden $807.42 246 1.5 69 BULK-0e5c84d4
9193 Bulk Product 4f8bcb59 Electronics $109.85 77 4.7 47 BULK-cdddab45
9194 Bulk Product 6a1b8ba8 Sports & Outdoors $125.47 461 2.5 58 BULK-a40f1e79
9195 Bulk Product 2e5914c8 Electronics $542.57 9 1.0 94 BULK-42fb6bcf
9196 Bulk Product c3f4ce71 Clothing $86.45 299 3.4 43 BULK-a9a6ef5f
9197 Bulk Product deca190d Clothing $404.59 122 1.2 95 BULK-6283996d
9198 Bulk Product fa62583d Toys & Games $112.45 169 2.7 90 BULK-b4e9f5e8
9199 Bulk Product 2697c052 Electronics $265.06 108 4.8 73 BULK-7af363b8
9200 Bulk Product a1fa1793 Electronics $246.62 184 2.6 38 BULK-39abac63
9201 Bulk Product e6ba822b Sports & Outdoors $587.86 119 0.4 66 BULK-1084be4d
9202 Bulk Product 7f8b3d48 Home & Garden $82.78 192 0.3 85 BULK-5ddc79b8
9203 Bulk Product 0f8839d5 Electronics $173.18 376 4.8 46 BULK-1daec9b1
9204 Bulk Product 598fffe6 Clothing $639.03 330 4.5 9 BULK-2ef1b603
9205 Bulk Product 74fda450 Clothing $709.86 311 3.4 79 BULK-1bcc4e2e
9206 Bulk Product 0dce83dc Home & Garden $729.96 325 0.0 18 BULK-952eda0b
9207 Bulk Product 6a1fde0f Books $470.63 433 3.9 20 BULK-7e09c829
9208 Bulk Product c81d4bf6 Toys & Games $722.24 124 3.0 33 BULK-f3e55548
9209 Bulk Product bf74d375 Books $747.11 398 4.5 95 BULK-a866d8ea
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