EF 6 生成的 Skip 和 Take 的 SQL 语句不起作用。

huangapple go评论60阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月29日 21:27:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76357796.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定