只有LINQ to实体中的排序输入才支持方法'skip'。必须在方法“skip”之前调用'orderby'方法。 [英] The method 'skip' is only supported for sorted input in LINQ to entities. The method 'orderby' must be called before the method 'skip'.'
本文介绍了只有LINQ to实体中的排序输入才支持方法'skip'。必须在方法“skip”之前调用'orderby'方法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public virtual IEnumerable<TEntity> Get(int? page, Expression<Func<TEntity,bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "")
{
IQueryable<TEntity> query = dbSet;
if (filter != null)
{
query = query.Where(filter);
}
foreach (var includeProperty in includeProperties.Split
(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
query = query.Include(includeProperty);
}
if (orderBy != null)
{
return orderBy(query).ToPagedList(page ?? 1, 5);
}
else
{
return query.ToPagedList(page ?? 1, 5);
}
}
我尝试过:
我正在使用通用存储库和pagedlist.mvc。
What I have tried:
I'm using generic repository and pagedlist.mvc.
推荐答案
通过提供非空值
orderBy
所以说你的名单是Person对象
So say your list was of Person object
public class Person
{
int Age{ get; set; }
}
我会尝试按如下方式调用回购代码
I would try calling the repo code as follows
...Get(page: 1, filter: x => x.Age > 5, orderBy: people => people.OrderBy(x => x.Age), includeProperties: "");
我想看看
ToPagedList()
看起来像某种扩展方法
这篇关于只有LINQ to实体中的排序输入才支持方法'skip'。必须在方法“skip”之前调用'orderby'方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文