Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to do pagination by using asp.net mvc core 1.2 .
I followed the below link
"https://www.reflectionit.nl/blog/2017/paging-in-asp-net-core-mvc-and-entityframework-core"

IQueryable<searchdata> qry = objReturnDoc.GetViewLogger(search).AsQueryable();

var result = await PagingList<searchdata>.CreateAsync(qry,3,1,null,null);
The above line throwing following error
An unhandled exception occurred while processing the request.

InvalidOperationException: The provider for the source IQueryable doesn't implement IAsyncQueryProvider. Only providers that implement IEntityQueryProvider can be used for Entity Framework asynchronous operations.

I agree , am not using Entity framework.  am using list..How to to fix it? Thanks in advance


What I have tried:

public async Task<iactionresult> ViewLog(string claimNum,string ReqId,string startDate,string endDate,int page)
{
SearchData search = new SearchData();

search.claimNum = claimNum;
if (startDate != null)
search.StartDate = startDate;

if (endDate != null)
search.EndDate = endDate;
search.claimNum = "8848948488";
search.rqID = ReqId;
ReturnDocRepository objReturnDoc = new ReturnDocRepository("mongodb://10.66.60.192:27017");
IQueryable<searchdata> qry = objReturnDoc.GetViewLogger(search).AsQueryable().
// am Getting error on below line
var result = await PagingList<searchdata>.CreateAsync(qry,3,1,null,null);
InvalidOperationException: The provider for the source IQueryable doesn't implement IAsyncQueryProvider. Only providers that implement IEntityQueryProvider can be used for Entity Framework asynchronous operations.

return View(result);

}
Posted
Updated 12-May-17 4:01am

1 solution

The data source you're using doesn't support async queries, and unfortunately, there isn't a synchronous overload of the Create method:
ReflectionIT.Mvc.Paging/PagingList.cs at master · sonnemaf/ReflectionIT.Mvc.Paging · GitHub[^]

The constructor is private, so you can't create your own version either.

You'll either need to fork the repository and add the method yourself, or log an issue on GitHub[^] to ask the author to add it for you.

The new methods would look something like this:
C#
public static PagingList<T> Create(IOrderedQueryable<T> qry, int pageSize, int pageIndex) {
    var pageCount = (int)Math.Ceiling(qry.Count() / (double)pageSize);

    return new PagingList<T>(qry.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(),
                             pageSize, pageIndex, pageCount);
}

public static PagingList<T> Create(IQueryable<T> qry, int pageSize, int pageIndex, string sortExpression, string defaultSortExpression) {
    var pageCount = (int)Math.Ceiling(qry.Count() / (double)pageSize);

    return new PagingList<T>(qry.OrderBy(sortExpression).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(),
                             pageSize, pageIndex, pageCount, sortExpression, defaultSortExpression);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900