【问题标题】:IQueryable OrderBy expression in .NET core.NET 核心中的 IQueryable OrderBy 表达式
【发布时间】:2016-06-27 08:22:49
【问题描述】:

在 .Net 核心库中,它不允许使用表达式作为参数调用 IQueryable.OrderBy

这是代码示例:

public class Elem
{
    public string Id { get; set; }
    public static IQueryable<Elem> SortById(IQueryable<Elem> paramSequence)
    {
        return paramSequence.OrderBy(x => x.Id);  //this gives error
    }
}

我添加了System.Linq.Expression 包。这是我的项目文件:

{
    "version": "1.0.0-*",
    "dependencies": {
        "NETStandard.Library": "1.5.0-rc2-24027",
        "System.Linq.Expressions": "4.0.10"
    },

    "frameworks": {
        "netstandard1.5": {
            "imports": "dnxcore50"
        }
    }
}

有什么想法吗?

【问题讨论】:

    标签: c# iqueryable .net-core


    【解决方案1】:

    System.Linq.Expressions 包含IQueryable&lt;T&gt;Expression&lt;TDelegate&gt;。但要使您的代码正常工作,您还需要包含IQueryable LINQ 扩展方法的类型:Queryable。这种类型在System.Linq.Queryable 包中。

    由于System.Linq.Queryable 依赖于System.Linq.Expressions,您可以将project.json 中的System.Linq.Expressions 行替换为:

    "System.Linq.Queryable": "4.0.1-rc2-24027"
    

    【讨论】:

    • 谢谢!它现在可以工作了(它向我添加了包 "System.Linq.Queryable": "4.0.0" 但也可以工作......)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    • 2023-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多