Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

330 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 330 Results Showing 8226 - 8250 of 24441

ID Name Category Price Stock Rating Reviews SKU
8785 Bulk Product cd36fb88 Toys & Games $516.63 449 2.9 12 BULK-948a879d
8786 Bulk Product 60280f4a Books $322.76 462 0.8 36 BULK-ed478901
8787 Bulk Product ccd397ae Books $478.78 6 3.1 9 BULK-4f6b003f
8788 Bulk Product fcb2019c Books $30.92 68 3.9 37 BULK-8ac4a86d
8789 Bulk Product 3aab636b Home & Garden $561.74 51 0.9 21 BULK-b7939d26
8790 Bulk Product 4d698914 Electronics $387.21 171 2.5 13 BULK-41f46700
8791 Bulk Product a32c2975 Books $652.71 150 0.5 13 BULK-0b53b034
8792 Bulk Product 4075164e Home & Garden $296.57 478 3.3 67 BULK-2d5f0234
8793 Bulk Product a81472aa Sports & Outdoors $194.50 50 2.8 56 BULK-405cf498
8794 Bulk Product 6eee4ade Clothing $799.41 110 2.9 46 BULK-abdae194
8795 Bulk Product 5fcf995d Clothing $927.62 243 4.9 37 BULK-84e403f0
8796 Bulk Product e875d324 Home & Garden $400.19 107 3.6 58 BULK-cd17a4ee
8797 Bulk Product 8f7a1ffb Clothing $641.43 480 2.6 8 BULK-aa53f74b
8798 Bulk Product 6fc0bdea Clothing $571.88 154 1.2 77 BULK-45f8183b
8799 Bulk Product f29bfeb1 Electronics $886.75 147 0.9 41 BULK-c86b923c
8800 Bulk Product 8e9eb6dc Clothing $651.19 402 4.5 27 BULK-7322490c
8801 Bulk Product 0a9f4b58 Toys & Games $977.07 123 1.1 82 BULK-8f2daa71
8802 Bulk Product 19766a55 Sports & Outdoors $437.72 325 0.9 1 BULK-f8bb59f8
8803 Bulk Product e6a3cecc Electronics $773.19 41 4.4 9 BULK-0a5c39d0
8804 Bulk Product 16a525ee Electronics $84.58 78 4.3 79 BULK-45f22cf6
8805 Bulk Product d2a80acf Sports & Outdoors $735.35 228 0.1 88 BULK-58fbe7ec
8806 Bulk Product 04c40036 Books $793.13 52 4.3 34 BULK-66a589e5
8807 Bulk Product 276b9aa1 Clothing $201.40 105 2.7 97 BULK-1564d4df
8808 Bulk Product bf6ce337 Home & Garden $185.34 334 1.1 20 BULK-4d6633ac
8809 Bulk Product 15129023 Electronics $232.33 241 1.6 91 BULK-c62ebc1b
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