c# – 如何使用Paginate方法
发布时间:2020-12-15 08:47:59 所属栏目:百科 来源:网络整理
导读:我在Web API项目中遇到了PaginatedList的问题. 在存储库中有一个方法,如: public virtual PaginatedListT PaginateTKey(int pageIndex,int pageSize,ExpressionFuncT,TKey keySelector,bool predicate,params ExpressionFuncT,object[] includeProperties){
我在Web API项目中遇到了PaginatedList的问题.
在存储库中有一个方法,如: public virtual PaginatedList<T> Paginate<TKey>(int pageIndex,int pageSize,Expression<Func<T,TKey>> keySelector,bool>> predicate,params Expression<Func<T,object>>[] includeProperties) { IQueryable<T> query = AllIncluding(includeProperties).OrderBy(keySelector); query = (predicate == null) ? query : query.Where(predicate); return query.ToPaginatedList(pageIndex,pageSize); } 但是,当我尝试使用它时,像这样: var a = repository.Paginate<Region>(pageNo,pageSize,x => x.ID,null); 我收到此错误:
我究竟做错了什么? 解决方法
你的方法签名有TKey,我想是一个排序的键,但在你的调用中你指定整个对象Region,然后你在keySelector中指定int,所以它不能编译它,因为它尝试使用int类型作为TKey的区域类型.
我想你的样本应该是: repository.Paginate<int>(pageNo,null); 通用类型T i假设是为整个类指定的,因此在此处应该没有在调用中指定它,因为存储库实例已经是特定于通用的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |