Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

29 ms

Page Size

25

Current Page

707 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 707 Results Showing 17651 - 17675 of 24441

ID Name Category Price Stock Rating Reviews SKU
18210 Bulk Product 0ea60ca7 Sports & Outdoors $831.66 3 1.5 48 BULK-1fb8550f
18211 Bulk Product 4badf915 Home & Garden $710.10 91 3.8 41 BULK-6a305fad
18212 Bulk Product f55056d2 Clothing $961.52 181 3.6 77 BULK-a4c537ea
18213 Bulk Product 57a6cb43 Electronics $32.69 167 1.2 79 BULK-4a95c1f5
18214 Bulk Product 0d428d99 Toys & Games $517.46 334 4.4 52 BULK-6dd4d962
18215 Bulk Product c3179c9e Home & Garden $529.88 14 3.5 48 BULK-92338866
18216 Bulk Product 78fbd725 Clothing $748.71 230 2.0 57 BULK-9cd693be
18217 Bulk Product cf3038e0 Home & Garden $429.55 433 2.8 61 BULK-3d20c61e
18218 Bulk Product 38355380 Electronics $833.05 357 2.0 95 BULK-d96818f9
18219 Bulk Product 30b5a08e Electronics $709.03 207 1.4 19 BULK-77d78798
18220 Bulk Product 1092c407 Clothing $630.54 375 2.5 53 BULK-06b20c6e
18221 Bulk Product f29e4196 Toys & Games $723.37 99 0.1 41 BULK-24c53103
18222 Bulk Product 5eaa8b98 Toys & Games $979.59 284 3.6 1 BULK-ef30df0c
18223 Bulk Product 823dd7e8 Electronics $354.36 273 0.3 32 BULK-1e4e2121
18224 Bulk Product fd3d05bf Clothing $757.67 85 2.4 9 BULK-e858e8ee
18225 Bulk Product 64607b60 Clothing $72.81 36 3.7 97 BULK-ecfe8b7f
18226 Bulk Product 392b6609 Toys & Games $678.10 190 1.3 56 BULK-a10cbbf6
18227 Bulk Product 4b164d0d Books $831.72 168 2.3 50 BULK-40b95bc5
18228 Bulk Product 5aa0550d Sports & Outdoors $982.51 79 2.6 87 BULK-cf6a17b3
18229 Bulk Product d1b0eeb7 Sports & Outdoors $514.07 161 4.5 54 BULK-2dadaa1d
18230 Bulk Product bff35ba1 Clothing $145.27 485 1.2 25 BULK-88031fd2
18231 Bulk Product 69c1b51b Electronics $939.33 306 2.0 89 BULK-cba3d529
18232 Bulk Product e40472ee Clothing $936.16 118 4.6 38 BULK-8d63b82a
18233 Bulk Product ac39cc39 Toys & Games $772.28 26 1.7 7 BULK-b4480e8d
18234 Bulk Product d8bc62c3 Electronics $475.42 45 2.5 4 BULK-1bef6aa7
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