Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

44 ms

Page Size

25

Current Page

229 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 229 Results Showing 5701 - 5725 of 24441

ID Name Category Price Stock Rating Reviews SKU
6260 Bulk Product 1aa7e025 Home & Garden $663.78 71 5.0 77 BULK-7efc790b
6261 Bulk Product 986dc20a Clothing $608.41 44 2.7 16 BULK-014f935d
6262 Bulk Product 78c8d800 Clothing $324.61 92 2.6 84 BULK-652138de
6263 Bulk Product c2f4de6e Home & Garden $608.50 51 0.0 74 BULK-1b85fa16
6264 Bulk Product fca891d4 Toys & Games $837.66 344 2.9 85 BULK-6fd34f67
6265 Bulk Product 06110b77 Clothing $264.07 429 0.8 43 BULK-46f6ed70
6266 Bulk Product c231e089 Books $912.09 17 3.5 99 BULK-1868cd8b
6267 Bulk Product 85d35d15 Clothing $566.35 141 0.3 61 BULK-d38767c5
6268 Bulk Product eaf0b7fd Toys & Games $185.05 164 2.2 65 BULK-b94508ea
6269 Bulk Product 1806cdf5 Electronics $751.82 116 1.8 65 BULK-bcaa3035
6270 Bulk Product 3ebf75b5 Sports & Outdoors $757.33 211 1.6 40 BULK-f9e7697b
6271 Bulk Product e89edb71 Books $407.98 32 0.4 18 BULK-9eef5f43
6272 Bulk Product 2a371c09 Electronics $502.57 270 3.7 98 BULK-f888a590
6273 Bulk Product 1e1df2d2 Electronics $523.10 92 4.8 23 BULK-ef0bfdba
6274 Bulk Product 6d032294 Home & Garden $902.37 214 4.4 77 BULK-67506c21
6275 Bulk Product 81b0f1b0 Home & Garden $516.22 430 1.1 95 BULK-b7a9fc35
6276 Bulk Product 304ca6a2 Toys & Games $790.75 318 2.0 70 BULK-14edd002
6277 Bulk Product 7adb6760 Sports & Outdoors $127.16 205 2.4 61 BULK-7e40ece9
6278 Bulk Product 907c18ff Clothing $996.40 313 4.5 9 BULK-44c6cc71
6279 Bulk Product 6d40967e Books $273.86 210 1.9 48 BULK-3a0c879a
6280 Bulk Product d3852107 Home & Garden $494.37 39 0.2 88 BULK-9d08746a
6281 Bulk Product d7facc69 Electronics $723.38 240 4.5 38 BULK-b6af0ae9
6282 Bulk Product 9d58278d Sports & Outdoors $484.27 222 1.7 22 BULK-5559dc3e
6283 Bulk Product 98138028 Clothing $913.35 4 2.4 7 BULK-57126cd2
6284 Bulk Product 2b1b33a7 Toys & Games $589.89 258 1.2 52 BULK-9fc36210
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