Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement “in Entity Framework core”

Dung Do Tien Dec 29 2020 243

I am implementing the paging function with Entity Framework, my code is as follows:

public PagedList(IQueryable<T> source, int pageIndex, int pageSize, bool getOnlyTotalCount = false)
    if (pageSize > PagedListHelper.MaxPageSize)
        throw new IChibaException(
            $"{nameof(pageSize)} must be less than or equal to {nameof(PagedListHelper.MaxPageSize)} (${PagedListHelper.MaxPageSize})");

    var total = source.Count();
    TotalCount = total;
    TotalPages = total / pageSize;

    if (total % pageSize > 0)

    PageSize = pageSize;
    PageIndex = pageIndex;
    if (getOnlyTotalCount)
    AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList());

When running with visual studio, the error "Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement" in Entity Framework core ". I'm using SQL server 2012 and Entity framework version 3.1.9

Please suggest to me how to solve this problem.

Have 1 answer(s) found.
  • This syntax must be SQL Server 2012 or higher to work because you are using the old SQL version compared to the Entity Framework version, so it is generating the new offset syntax of SQL Server 2012.

    Dũng Đô La Dec 29 2020
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips