Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

71 ms

Page Size

25

Current Page

738 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 738 Results Showing 18426 - 18450 of 24441

ID Name Category Price Stock Rating Reviews SKU
18985 Bulk Product 189f6384 Books $794.02 169 3.9 64 BULK-99b08967
18986 Bulk Product a98caeb4 Electronics $275.21 213 4.5 94 BULK-2c2127ac
18987 Bulk Product 7d7e85e3 Clothing $108.14 266 4.6 51 BULK-b0089aeb
18988 Bulk Product 2aac6ec4 Home & Garden $616.48 327 2.6 4 BULK-07dcff1d
18989 Bulk Product 11409f7c Sports & Outdoors $826.06 464 0.7 26 BULK-c610c7f4
18990 Bulk Product a3047527 Electronics $413.02 482 2.2 4 BULK-9a2380ea
18991 Bulk Product a8ac7c80 Clothing $573.38 332 0.9 96 BULK-e050a2b2
18992 Bulk Product b7447932 Clothing $810.00 370 0.5 77 BULK-6c58225e
18993 Bulk Product 3a89cbcb Books $904.76 129 5.0 4 BULK-01a160df
18994 Bulk Product 78660b0b Sports & Outdoors $456.03 180 0.5 2 BULK-599948b9
18995 Bulk Product 4af2b64b Home & Garden $402.39 168 2.3 29 BULK-72a94e6b
18996 Bulk Product 6dda880e Sports & Outdoors $612.44 402 0.5 70 BULK-c7a0e676
18997 Bulk Product 1f382cb9 Books $255.80 127 0.3 19 BULK-ea70c169
18998 Bulk Product a56bdac5 Clothing $280.80 212 3.4 11 BULK-8193b530
18999 Bulk Product d3df993e Electronics $472.51 458 0.3 16 BULK-086ce1ee
19000 Bulk Product 0e91a6f2 Clothing $522.78 284 1.0 46 BULK-7bd56708
19001 Bulk Product f87850ea Toys & Games $323.53 189 3.5 44 BULK-1612db1a
19002 Bulk Product cbefbefa Home & Garden $525.16 119 2.9 24 BULK-590325ff
19003 Bulk Product 729e53c8 Sports & Outdoors $373.02 391 4.3 22 BULK-8c720f02
19004 Bulk Product 650329e0 Books $758.49 426 4.0 1 BULK-b1e312e7
19005 Bulk Product 41b8e310 Sports & Outdoors $970.12 209 1.2 50 BULK-75df1a04
19006 Bulk Product 7e96dff9 Toys & Games $919.64 302 2.3 9 BULK-d736fafe
19007 Bulk Product aaa4501a Clothing $333.26 310 0.7 94 BULK-294e6902
19008 Bulk Product 58a922ef Home & Garden $352.74 411 1.7 32 BULK-eedf5ff5
19009 Bulk Product a2b33218 Clothing $140.17 92 3.3 73 BULK-0e5a52fa
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