Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

770 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 770 Results Showing 19226 - 19250 of 24441

ID Name Category Price Stock Rating Reviews SKU
19785 Bulk Product 55f0ad1a Toys & Games $762.34 11 0.4 7 BULK-e9b2c4cd
19786 Bulk Product c3f9527f Home & Garden $564.97 242 0.9 4 BULK-bf0926a4
19787 Bulk Product b1e2b9ea Toys & Games $142.22 391 1.3 57 BULK-7e634aab
19788 Bulk Product b2f6fd1b Clothing $428.72 134 2.3 18 BULK-217df683
19789 Bulk Product 8682bb95 Books $340.70 404 4.2 80 BULK-de50f763
19790 Bulk Product 7da9fabe Electronics $563.59 50 1.4 76 BULK-abcde8ab
19791 Bulk Product 04ca4df3 Books $574.36 460 3.9 45 BULK-64e50766
19792 Bulk Product 3954739c Clothing $309.72 319 3.6 51 BULK-d57f2623
19793 Bulk Product 6d17948f Toys & Games $318.77 226 2.9 50 BULK-a20797fd
19794 Bulk Product fbe79ebc Sports & Outdoors $558.00 373 0.3 70 BULK-76e94d76
19795 Bulk Product e1546ee5 Home & Garden $22.03 173 2.6 34 BULK-ca4f71b9
19796 Bulk Product fed4efce Home & Garden $84.73 73 3.4 81 BULK-8273810b
19797 Bulk Product 8dbc2ff5 Books $10.97 224 4.8 51 BULK-d0982648
19798 Bulk Product 2c6e7f42 Clothing $465.64 204 2.6 1 BULK-b76fe253
19799 Bulk Product ee9b2bf1 Sports & Outdoors $409.36 21 1.1 85 BULK-06dc64ea
19800 Bulk Product 0d14b160 Sports & Outdoors $704.21 147 4.8 86 BULK-47a2f686
19801 Bulk Product d061118d Electronics $459.84 158 4.6 19 BULK-374e58d4
19802 Bulk Product 6d62f3b4 Home & Garden $53.24 184 2.4 46 BULK-22b1a081
19803 Bulk Product 11ad4708 Electronics $324.84 349 1.1 21 BULK-0aa154d0
19804 Bulk Product 1caba4b7 Home & Garden $158.48 347 1.3 56 BULK-ff390d59
19805 Bulk Product e6c9deae Home & Garden $703.35 177 4.7 99 BULK-bbae0005
19806 Bulk Product 2fa379fd Books $670.44 104 4.2 31 BULK-ce1aef76
19807 Bulk Product 5316bfc5 Clothing $872.07 331 1.0 70 BULK-e2ee9917
19808 Bulk Product 99e3fbb3 Books $197.04 350 0.5 57 BULK-24d8184c
19809 Bulk Product 925f2943 Toys & Games $647.45 31 4.0 8 BULK-b5c9aa54
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