问题描述
我正在尝试使用asp.net mvc core 1.2进行分页。
我按照以下链接
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) ;
以上行抛出以下错误
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
我的尝试:
公共异步任务< 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在线下获得错误
var result = await PagingList< searchdata> .CreateAsync(qry, 3,1,NULL,NULL);
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);
}
推荐答案
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);
}
这篇关于使用reflectionit.mvc.paging的Asp.net MVC核心分页;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!