Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

618 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 618 Results Showing 15426 - 15450 of 24441

ID Name Category Price Stock Rating Reviews SKU
15985 Bulk Product 4f16b4c1 Home & Garden $128.05 47 1.8 67 BULK-63442f20
15986 Bulk Product 17d8709f Sports & Outdoors $477.96 260 3.4 82 BULK-cc14f199
15987 Bulk Product 2705eb0f Toys & Games $771.62 1 0.6 51 BULK-0e4acf8e
15988 Bulk Product 941ff6fb Home & Garden $944.47 437 1.1 67 BULK-31839b65
15989 Bulk Product 2ec999b5 Books $860.25 354 0.2 37 BULK-83e69162
15990 Bulk Product 030cfcba Books $918.88 215 0.3 84 BULK-f3d480f9
15991 Bulk Product 0ce923f1 Books $312.60 4 2.5 9 BULK-0714e0a2
15992 Bulk Product d61998b0 Clothing $540.62 495 0.3 67 BULK-2192b730
15993 Bulk Product 5a3017b1 Toys & Games $542.57 333 1.1 16 BULK-8dbebfd8
15994 Bulk Product f73a274e Home & Garden $1,008.96 27 4.6 55 BULK-9165ea07
15995 Bulk Product 3fcca318 Home & Garden $983.51 409 2.3 5 BULK-e918016f
15996 Bulk Product 5cec4154 Electronics $917.04 206 0.6 29 BULK-b7a14ccd
15997 Bulk Product cad4dc9c Electronics $630.07 61 0.6 42 BULK-27114f7d
15998 Bulk Product 3dbc94ec Sports & Outdoors $952.16 96 1.2 79 BULK-3c288ce6
15999 Bulk Product 13ce3713 Books $479.63 3 2.2 20 BULK-2ac1252c
16000 Bulk Product acc6991c Sports & Outdoors $390.66 159 1.2 43 BULK-ba54118e
16001 Bulk Product a1e8f4c5 Clothing $832.82 490 4.6 36 BULK-5287afd5
16002 Bulk Product 3e930ff5 Clothing $379.52 355 4.1 6 BULK-97fc878b
16003 Bulk Product a221a522 Home & Garden $820.24 350 3.8 56 BULK-4d62392e
16004 Bulk Product 5b71c85e Toys & Games $133.01 166 1.7 57 BULK-616dd1fe
16005 Bulk Product 15d351b0 Books $713.74 299 1.0 50 BULK-28725491
16006 Bulk Product 698fcf1b Books $698.80 162 2.4 51 BULK-6b578021
16007 Bulk Product bc8d01d8 Home & Garden $997.91 80 3.9 73 BULK-c2bfc61d
16008 Bulk Product 46391dd7 Home & Garden $989.70 484 2.7 82 BULK-6b746c34
16009 Bulk Product 9aadbcd8 Sports & Outdoors $123.26 236 2.6 40 BULK-ab52d836
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