Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

39 ms

Page Size

25

Current Page

340 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 340 Results Showing 8476 - 8500 of 24441

ID Name Category Price Stock Rating Reviews SKU
9035 Bulk Product 1f38760a Clothing $231.88 173 2.1 66 BULK-c4b2bc9a
9036 Bulk Product 46814be6 Sports & Outdoors $192.60 152 0.1 84 BULK-b2a01495
9037 Bulk Product 00463da1 Clothing $730.23 263 1.5 49 BULK-99fcdfbb
9038 Bulk Product 74d1353c Books $356.30 74 4.5 25 BULK-7c23af0c
9039 Bulk Product 12f7fd31 Home & Garden $569.63 133 2.6 34 BULK-6b25084f
9040 Bulk Product f49b3def Clothing $409.00 201 2.7 99 BULK-8a13749c
9041 Bulk Product 3104670d Home & Garden $880.65 194 4.6 45 BULK-574535bb
9042 Bulk Product 946c4a5a Clothing $667.16 489 2.5 84 BULK-f1fdd1d0
9043 Bulk Product 2a9917f4 Home & Garden $202.18 448 2.8 68 BULK-25619077
9044 Bulk Product a0f59b9c Home & Garden $482.08 391 4.8 46 BULK-67a5b654
9045 Bulk Product a5777bb5 Books $974.22 304 0.1 66 BULK-82777824
9046 Bulk Product 09e22686 Clothing $946.01 20 5.0 95 BULK-ac32683f
9047 Bulk Product 20d2732c Clothing $789.50 187 3.7 19 BULK-a6c4fd91
9048 Bulk Product c1574c84 Clothing $728.92 135 4.9 13 BULK-fee4f3a7
9049 Bulk Product 66eae88e Toys & Games $18.57 22 0.3 8 BULK-a8238e2c
9050 Bulk Product b16a5156 Books $41.04 142 2.5 35 BULK-5de7e27a
9051 Bulk Product 47c104ce Sports & Outdoors $390.12 450 1.1 18 BULK-8e35f653
9052 Bulk Product 8280b583 Electronics $752.62 293 2.3 71 BULK-ec3659ba
9053 Bulk Product 5f388cc3 Toys & Games $402.84 50 0.3 90 BULK-48e458a9
9054 Bulk Product 1c234c0c Books $157.59 462 4.8 42 BULK-b139cb04
9055 Bulk Product 571cff46 Sports & Outdoors $908.23 287 1.1 1 BULK-f857b199
9056 Bulk Product a5be8374 Sports & Outdoors $710.75 263 3.2 95 BULK-c43f1ee7
9057 Bulk Product 681c110d Books $440.82 9 2.7 28 BULK-876518ca
9058 Bulk Product 36cbf715 Clothing $788.56 497 1.7 69 BULK-ea528f00
9059 Bulk Product 3d560853 Toys & Games $775.55 241 1.2 86 BULK-0e9c8955
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