英文:
EF 6 Generated SQL from Skip and Take does not work
问题
The SQL generated by the newQuery
does not have the OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY.
这个newQuery
生成的SQL没有 OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY。
英文:
The sql generated by the newQuery
does not have the OFFSET 0 ROWS
FETCH NEXT 1 ROWS ONLY
public IList<T> GetManyOrderByDescending<TProperty>(Expression<Func<T, bool>> where, Func<T, TProperty> orderBySelector, int page, int pageSize, params Expression<Func<T, object>>[] includes)
{
var query = includes.Aggregate(DbSet, (current, item) => current.Include(item));
var newQuery = query.AsExpandable().Where(where).OrderByDescending(orderBySelector).Skip((page - 1) * pageSize).Take(pageSize);
return newQuery.ToList();
}
This is how it is used:
var predicate = PredicateBuilder.True<T>();
predicate = predicate.And(x => x.Age < 40);
var list = _customerService.OrderByDescending(predicate, x => x.Name, 1, 10, x => x.CustomerType);
答案1
得分: 0
将Func<T, TProperty> orderBySelector
更改为表达式Expression<Func<T, TProperty>>
解决了问题。感谢@GertArnold的评论。
英文:
Changing the Func<T, TProperty> orderBySelector
to an expression Expression<Func<T, TProperty>>
solved the issue. Thanks to @GertArnold's comment
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论