Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

728 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 728 Results Showing 18176 - 18200 of 24441

ID Name Category Price Stock Rating Reviews SKU
18735 Bulk Product c4a80e23 Clothing $497.64 358 0.2 46 BULK-476afc79
18736 Bulk Product f835449e Sports & Outdoors $839.16 278 1.5 50 BULK-390fd65f
18737 Bulk Product dbbe9c57 Home & Garden $852.51 242 4.5 83 BULK-1a8fbe16
18738 Bulk Product 318c8593 Home & Garden $255.06 410 1.4 24 BULK-99148bbf
18739 Bulk Product c553b390 Sports & Outdoors $170.77 109 2.4 58 BULK-ba25bf55
18740 Bulk Product 798feab0 Books $816.34 272 4.8 53 BULK-4a3885f9
18741 Bulk Product 8c63f981 Home & Garden $664.60 105 1.7 96 BULK-a460018c
18742 Bulk Product 68702225 Home & Garden $631.12 418 3.8 40 BULK-a836a802
18743 Bulk Product e5c75b2e Home & Garden $826.90 54 4.1 79 BULK-62c2d68e
18744 Bulk Product 23b7d228 Electronics $559.17 430 2.4 40 BULK-a8d05345
18745 Bulk Product 726ff87e Toys & Games $48.58 302 5.0 48 BULK-f19e205b
18746 Bulk Product 4ef325a0 Sports & Outdoors $736.17 165 3.6 34 BULK-edd66c33
18747 Bulk Product 2d76e371 Books $405.59 464 4.5 48 BULK-115f8693
18748 Bulk Product 2fa83a64 Books $399.32 365 0.8 15 BULK-9bd7ad1f
18749 Bulk Product 4d08ecd0 Home & Garden $738.28 111 4.6 17 BULK-7cfea171
18750 Bulk Product f24af1e0 Home & Garden $19.23 94 3.7 63 BULK-495d9165
18751 Bulk Product 24e3ebe9 Books $934.10 117 2.4 63 BULK-0cfe6214
18752 Bulk Product df5158b3 Electronics $806.86 226 2.1 74 BULK-ede41a27
18753 Bulk Product 51dc75d5 Toys & Games $379.76 497 3.4 44 BULK-017bfbeb
18754 Bulk Product 93da3bd2 Electronics $868.46 61 3.6 71 BULK-8642e860
18755 Bulk Product aad63ff7 Toys & Games $316.76 294 3.8 40 BULK-c16cd743
18756 Bulk Product 82c8a018 Books $314.88 88 0.6 13 BULK-5622994b
18757 Bulk Product d3d4db67 Toys & Games $515.48 251 3.8 81 BULK-6b16594d
18758 Bulk Product 965e4dee Books $287.96 319 2.2 37 BULK-11808cd5
18759 Bulk Product 19ceac18 Toys & Games $971.45 37 2.6 1 BULK-ea573266
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