Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

946 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 946 Results Showing 23626 - 23650 of 24441

ID Name Category Price Stock Rating Reviews SKU
24185 Bulk Product 73f9957f Clothing $389.42 155 0.2 77 BULK-33738345
24186 Bulk Product ecf77986 Clothing $690.46 276 0.5 73 BULK-80ac7112
24187 Bulk Product 8be59984 Clothing $898.48 235 2.0 97 BULK-84f1b10c
24188 Bulk Product ae7ddbcf Sports & Outdoors $494.07 243 4.4 37 BULK-f4ef1a1b
24189 Bulk Product e1a18df4 Home & Garden $484.60 376 0.5 22 BULK-494f54a5
24190 Bulk Product 172905b3 Sports & Outdoors $984.90 268 1.2 64 BULK-1a983401
24191 Bulk Product bb3628e2 Sports & Outdoors $583.91 44 0.5 27 BULK-0f71371b
24192 Bulk Product c1a85250 Clothing $126.42 293 4.4 49 BULK-133f3051
24193 Bulk Product e4102f06 Electronics $181.22 71 1.8 98 BULK-f59170d9
24194 Bulk Product ed11d18c Clothing $669.20 400 2.5 1 BULK-f125e4f9
24195 Bulk Product 4123ad7e Electronics $906.95 333 4.7 70 BULK-ae0179eb
24196 Bulk Product 866c4092 Books $384.19 133 3.2 14 BULK-1c8c15a6
24197 Bulk Product 32aec0ee Books $727.68 56 4.4 69 BULK-2559da34
24198 Bulk Product 4f1061c6 Electronics $508.74 249 2.6 71 BULK-6be0c851
24199 Bulk Product 744da551 Sports & Outdoors $73.13 405 1.9 49 BULK-b49e6c83
24200 Bulk Product e0eed6b1 Books $304.77 208 2.8 24 BULK-9586e2f8
24201 Bulk Product 53bfad43 Home & Garden $563.01 200 2.6 12 BULK-08f9ffd1
24202 Bulk Product fc0fcffa Toys & Games $414.43 337 1.7 2 BULK-576e97a6
24203 Bulk Product d3a41ae8 Sports & Outdoors $503.12 38 3.2 13 BULK-80339d76
24204 Bulk Product cbadd1fc Clothing $488.25 250 1.6 36 BULK-19fba86b
24205 Bulk Product 3d04f70a Books $165.35 382 2.0 34 BULK-25f312dc
24206 Bulk Product dbdc21cb Toys & Games $1,006.50 104 3.5 89 BULK-fd610bd4
24207 Bulk Product 2f9c7963 Sports & Outdoors $339.15 25 4.4 85 BULK-4b3f3be8
24208 Bulk Product c998a7aa Electronics $623.92 149 3.4 55 BULK-75ca4b30
24209 Bulk Product 6346e790 Electronics $339.71 422 3.9 47 BULK-94bf2a41
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