Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

945 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 945 Results Showing 23601 - 23625 of 24441

ID Name Category Price Stock Rating Reviews SKU
24160 Bulk Product 6930e6df Books $874.38 0 2.6 50 BULK-1bf52115
24161 Bulk Product c7518070 Home & Garden $745.51 477 3.5 71 BULK-b2c5fed4
24162 Bulk Product 58f2b7e0 Toys & Games $1,005.31 451 4.0 45 BULK-db626b51
24163 Bulk Product 66ecaa65 Clothing $811.18 448 4.6 10 BULK-78ddcac1
24164 Bulk Product 71a99f56 Sports & Outdoors $359.99 362 4.1 84 BULK-c965d749
24165 Bulk Product 2190dda6 Electronics $581.96 278 0.3 99 BULK-e051ad9f
24166 Bulk Product 9546db1c Toys & Games $263.98 213 3.1 74 BULK-88b08f86
24167 Bulk Product 34d9baf9 Toys & Games $168.41 26 1.6 86 BULK-6a461e81
24168 Bulk Product d2de2136 Clothing $874.02 253 2.3 6 BULK-748c2a0e
24169 Bulk Product 25f40a77 Electronics $207.72 337 4.6 95 BULK-171485b6
24170 Bulk Product b4712d09 Toys & Games $474.96 434 1.1 26 BULK-4f924d60
24171 Bulk Product 0323b1a7 Electronics $388.20 131 3.9 16 BULK-3a639307
24172 Bulk Product ddd7fe9d Electronics $265.72 327 2.2 5 BULK-d9b4bab3
24173 Bulk Product 444be965 Books $848.45 98 2.5 24 BULK-ece8401f
24174 Bulk Product d49110aa Electronics $401.77 103 0.5 40 BULK-b315a7c3
24175 Bulk Product 49c35604 Books $672.28 404 2.9 2 BULK-38fbd21c
24176 Bulk Product 5d95aee6 Home & Garden $50.73 119 0.5 84 BULK-8f3df6e2
24177 Bulk Product 0f03d507 Home & Garden $218.52 356 3.5 60 BULK-c11e3eeb
24178 Bulk Product d187606d Toys & Games $229.68 277 3.3 25 BULK-59109421
24179 Bulk Product e2618806 Clothing $563.89 209 1.0 55 BULK-1eb5cc26
24180 Bulk Product d4e3b3ee Books $204.07 310 1.6 47 BULK-a02e9eeb
24181 Bulk Product 7bde1e57 Home & Garden $913.76 89 1.5 55 BULK-e72f2a0e
24182 Bulk Product 009748a0 Electronics $666.67 20 2.8 81 BULK-28b78940
24183 Bulk Product 63035bbb Toys & Games $545.88 450 0.2 20 BULK-f78fe310
24184 Bulk Product a654f25f Books $188.62 180 0.8 46 BULK-61c32a76
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