使用reflectionit.mvc.paging的Asp.net MVC核心分页; [英] Asp.net MVC core pagination using reflectionit.mvc.paging;

查看:127
本文介绍了使用reflectionit.mvc.paging的Asp.net MVC核心分页;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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);

}

推荐答案

您使用的数据源不支持 async 查询,不幸的是,那里不是 Create 方法的同步重载:

在master·sonnemaf上的ReflectionIT.Mvc.Paging / PagingList.cs / ReflectionIT.Mvc.Paging·GitHub [ ^ ]



构造函数是 private ,因此你也无法创建自己的版本。



您需要分叉存储库并自行添加方法或在GitHub上记录问题 [ ^ ]要求作者为您添加。



新方法看起来像这样:

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:
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核心分页;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆