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

Dung Do Tien Dec 29 2020 643

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)
        TotalPages++;

    PageSize = pageSize;
    PageIndex = pageIndex;
    if (getOnlyTotalCount)
        return;
    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.

No answer found.
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

X Close