在 .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"
}
}
}
有什么想法吗?
最佳答案
包裹System.Linq.Expressions
包含 IQueryable<T>
和 Expression<TDelegate>
.但是为了使您的代码正常工作,您还需要包含 IQueryable
的类型LINQ 扩展方法:Queryable
.此类型在 System.Linq.Queryable
中包。
自 System.Linq.Queryable
取决于 System.Linq.Expressions
, 你可以替换 System.Linq.Expressions
在你的 project.json 行中:
"System.Linq.Queryable": "4.0.1-rc2-24027"
关于c# - .NET 核心中的 IQueryable OrderBy 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38049042/