Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

338 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 338 Results Showing 8426 - 8450 of 24441

ID Name Category Price Stock Rating Reviews SKU
8985 Bulk Product 804ff9ed Electronics $860.84 57 2.4 62 BULK-ecf034bc
8986 Bulk Product 085f9543 Books $478.90 314 0.9 69 BULK-e457947f
8987 Bulk Product 4b08f2a7 Books $633.86 27 2.5 43 BULK-5712c104
8988 Bulk Product 1c6ebb85 Books $238.20 174 2.1 20 BULK-c61b52f4
8989 Bulk Product f2a89bf5 Books $374.08 385 1.7 71 BULK-943e21de
8990 Bulk Product 6d195744 Electronics $15.97 232 0.0 50 BULK-4a675898
8991 Bulk Product ded889e7 Electronics $726.53 141 4.2 45 BULK-6afd720b
8992 Bulk Product 7433accd Toys & Games $66.15 23 3.5 65 BULK-b156d7bc
8993 Bulk Product 75f8baa7 Home & Garden $70.15 236 2.3 71 BULK-04279501
8994 Bulk Product 76283937 Toys & Games $762.18 370 2.3 58 BULK-cfcc1ec6
8995 Bulk Product 302ea1a5 Toys & Games $301.50 74 3.7 98 BULK-4853b237
8996 Bulk Product 6f0c4587 Home & Garden $996.19 48 4.3 19 BULK-aaf86133
8997 Bulk Product 8b5c9e9d Toys & Games $438.04 393 3.9 46 BULK-8bf34560
8998 Bulk Product 16e69e4b Sports & Outdoors $893.59 312 0.9 73 BULK-bc31e1a7
8999 Bulk Product 73fcc71b Home & Garden $1,006.72 419 2.8 52 BULK-cd3601c4
9000 Bulk Product 31d0f367 Toys & Games $999.97 56 4.9 39 BULK-b19c1c95
9001 Bulk Product 87ffe83b Electronics $674.70 151 1.1 84 BULK-c45f6b46
9002 Bulk Product 0b8dba5a Clothing $121.77 292 4.2 45 BULK-f0af84c9
9003 Bulk Product 6624c4c7 Sports & Outdoors $595.47 499 3.2 96 BULK-ad0fbd09
9004 Bulk Product 2b5f5e00 Clothing $238.96 273 2.5 74 BULK-33708f4f
9005 Bulk Product 03cc9281 Books $1,003.82 335 2.2 11 BULK-b5bc3b66
9006 Bulk Product e8a57842 Toys & Games $1,001.66 143 4.0 82 BULK-7198d82a
9007 Bulk Product 21e65e07 Home & Garden $835.74 379 1.1 0 BULK-b6030a2c
9008 Bulk Product 8df8cf11 Electronics $774.48 261 2.5 20 BULK-c0159ae5
9009 Bulk Product 67729e82 Electronics $813.00 187 3.6 36 BULK-5471dbb2
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