Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

227 ms

Page Size

25

Current Page

780 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 780 Results Showing 19476 - 19500 of 24441

ID Name Category Price Stock Rating Reviews SKU
20035 Bulk Product 722e2f95 Toys & Games $920.60 330 0.3 25 BULK-e331df57
20036 Bulk Product 9da9c63f Electronics $299.01 287 3.5 34 BULK-337dd949
20037 Bulk Product 3a4d742f Electronics $382.55 415 0.8 80 BULK-13fb0c8f
20038 Bulk Product 62a933fe Electronics $336.75 424 3.3 2 BULK-8557afb3
20039 Bulk Product 1921e507 Sports & Outdoors $232.61 281 0.3 39 BULK-54bb6cb7
20040 Bulk Product d48d6ecb Electronics $412.17 410 0.1 63 BULK-86b21721
20041 Bulk Product 3f83d58a Home & Garden $696.03 97 3.8 61 BULK-17e1696c
20042 Bulk Product ff066bf2 Books $552.02 264 3.9 28 BULK-fc202e84
20043 Bulk Product d5401ecb Home & Garden $263.93 394 0.1 35 BULK-59818242
20044 Bulk Product c71c3cb3 Books $131.44 412 3.5 24 BULK-22b16299
20045 Bulk Product c3eda44e Home & Garden $774.88 480 3.8 96 BULK-c3a21242
20046 Bulk Product 98a9ad7e Home & Garden $967.99 346 2.3 40 BULK-fb62ec5e
20047 Bulk Product c014d2e2 Electronics $966.42 24 1.0 31 BULK-b1b944a6
20048 Bulk Product c7ebabcc Sports & Outdoors $455.12 11 2.3 63 BULK-eb9b76dd
20049 Bulk Product 54a8be82 Clothing $834.04 243 3.2 19 BULK-92572ca1
20050 Bulk Product e3577941 Home & Garden $13.09 399 3.8 71 BULK-d7f6a10c
20051 Bulk Product 445a8c59 Sports & Outdoors $340.07 12 3.0 35 BULK-23646cc2
20052 Bulk Product 3b35444a Clothing $377.75 476 1.6 8 BULK-44a61a1e
20053 Bulk Product 1a39029e Home & Garden $459.57 67 4.6 72 BULK-661e6ded
20054 Bulk Product 2b370753 Sports & Outdoors $208.77 254 3.2 1 BULK-44d134c5
20055 Bulk Product 264c3488 Sports & Outdoors $317.15 83 1.2 24 BULK-cd67e160
20056 Bulk Product a00ce2b5 Home & Garden $501.14 81 3.1 91 BULK-a894d4df
20057 Bulk Product 0fbfb327 Sports & Outdoors $470.28 411 4.1 11 BULK-a6148101
20058 Bulk Product 3c1ed045 Toys & Games $408.17 423 1.5 58 BULK-02fdb7f2
20059 Bulk Product 07400f1f Books $365.59 127 4.7 88 BULK-90d4ea96
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