Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

31 ms

Page Size

25

Current Page

483 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 483 Results Showing 12051 - 12075 of 24441

ID Name Category Price Stock Rating Reviews SKU
12610 Bulk Product 9e54f32c Clothing $42.90 167 4.3 17 BULK-035d7cc5
12611 Bulk Product 0809a186 Books $78.48 3 1.1 16 BULK-e487d9eb
12612 Bulk Product 5e55b04c Sports & Outdoors $596.70 241 0.9 62 BULK-d9345685
12613 Bulk Product 9c0d32c2 Home & Garden $582.87 406 2.1 76 BULK-5c04b769
12614 Bulk Product dddd5aed Sports & Outdoors $940.97 72 0.7 57 BULK-835f3735
12615 Bulk Product 6f54323f Electronics $526.70 41 4.8 35 BULK-091d0a56
12616 Bulk Product 83361058 Home & Garden $660.69 336 0.7 61 BULK-c8780616
12617 Bulk Product 2cc41f9f Clothing $695.58 482 2.1 5 BULK-7492614b
12618 Bulk Product 21d4e107 Electronics $678.59 468 1.3 38 BULK-b7e21358
12619 Bulk Product b65656a1 Home & Garden $334.14 108 4.2 86 BULK-d767dc81
12620 Bulk Product 1fed288e Toys & Games $677.13 101 1.5 40 BULK-a88458fe
12621 Bulk Product e6a140ef Books $687.30 291 1.5 73 BULK-bd9b2220
12622 Bulk Product 70db4373 Toys & Games $562.99 362 1.3 77 BULK-1b63cb74
12623 Bulk Product 80053337 Toys & Games $218.18 121 4.0 34 BULK-923b2d8a
12624 Bulk Product 6d6b7671 Clothing $574.18 162 5.0 31 BULK-e3bf029e
12625 Bulk Product 0cd9d389 Sports & Outdoors $438.23 267 0.5 91 BULK-37d4afa5
12626 Bulk Product 19d416fc Toys & Games $783.71 383 1.3 92 BULK-8a076830
12627 Bulk Product f9f440b2 Toys & Games $678.84 432 4.5 31 BULK-35732d13
12628 Bulk Product f449502b Home & Garden $441.96 310 3.3 91 BULK-da8f06ba
12629 Bulk Product 0a5e7770 Sports & Outdoors $448.72 487 1.5 1 BULK-294232d3
12630 Bulk Product 5ffd87b6 Home & Garden $493.34 431 3.5 69 BULK-9e411b34
12631 Bulk Product 323bd971 Sports & Outdoors $294.42 245 0.2 60 BULK-04517dfc
12632 Bulk Product 0ae2e541 Home & Garden $606.30 265 3.1 46 BULK-2c349904
12633 Bulk Product 54e540de Clothing $474.65 340 1.7 23 BULK-f4e187f5
12634 Bulk Product 1cb31a35 Clothing $444.56 178 4.5 60 BULK-fce2da9a
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