Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法转换Linq.IORDerenumerable<;T>;致Linq.IQueryable<;T>;_C#_Asp.net Mvc_Linq - Fatal编程技术网

C# 无法转换Linq.IORDerenumerable<;T>;致Linq.IQueryable<;T>;

C# 无法转换Linq.IORDerenumerable<;T>;致Linq.IQueryable<;T>;,c#,asp.net-mvc,linq,C#,Asp.net Mvc,Linq,试图将orderby语句添加到我的通用存储库方法中,并出现以下错误。不确定为什么,因为在其他情况下,我似乎能够将.OrderBy添加到IQueryable 我错过了什么 获取错误: 无法将类型“System.Linq.iorderenumerable”隐式转换为“System.Linq.IQueryable” 代码段(已删除某些部分): 公共类QuickbooksRespository 其中TEntity:class,Intuit.Ipp.Data.IEntity,new() { 公共虚拟IQu

试图将
orderby
语句添加到我的通用存储库方法中,并出现以下错误。不确定为什么,因为在其他情况下,我似乎能够将.OrderBy添加到IQueryable

我错过了什么

获取错误:

无法将类型“System.Linq.iorderenumerable”隐式转换为“System.Linq.IQueryable”

代码段(已删除某些部分):

公共类QuickbooksRespository
其中TEntity:class,Intuit.Ipp.Data.IEntity,new()
{
公共虚拟IQueryable GetAll(
int page,int pageSize,
Func orderbyascending=null,
Func orderbydescending=null)
{
int skip=Math.Max(pageSize*(第1页),0);
IQueryable结果=\u qbQueryService
.选择(全部=>全部);
if(orderbyascending!=null)
{
结果=results.OrderBy(orderbyascending);
}
if(orderbydescending!=null)
{
结果=结果.OrderByDescending(OrderByDescending);
}
返回结果
.Skip(Skip)
。取(页面大小);
}
}

因为您提供了
Func
委托,所以选择了
IEnumerable.OrderBy
扩展方法。将方法参数更改为
表达式

公共虚拟IQueryable GetAll(
int page,int pageSize,
表达式orderbyascending=null,
表达式orderbydescending=null)

当您稍后实际调用
OrderBy()
时,将选择
IQueryable.OrderBy()
方法,而不是
IEnumerable.OrderBy()

谢谢,谢谢!他在拔我的头发。我对这样的表达式和函数还没有太多的经验。
public class QuickbooksRespository<TEntity>
         where TEntity : class, Intuit.Ipp.Data.IEntity, new()
    {
    public virtual IQueryable<TEntity> GetAll(
        int page, int pageSize,
        Func<TEntity, object> orderbyascending = null,
        Func<TEntity, object> orderbydescending = null)
    {
        int skip = Math.Max(pageSize * (page - 1), 0);

        IQueryable<TEntity> results = _qbQueryService
                .Select(all => all);

        if (orderbyascending != null)
        {
            results = results.OrderBy(orderbyascending);
        }

        if (orderbydescending != null)
        {
            results = results.OrderByDescending(orderbydescending);
        }

        return results
                .Skip(skip)
                .Take(pageSize);
    }
}
public virtual IQueryable<TEntity> GetAll(
    int page, int pageSize,
    Expression<Func<TEntity, object>> orderbyascending = null,
    Expression<Func<TEntity, object>> orderbydescending = null)