[英]'System.Linq.IQueryable' does not contain a definition for 'GroupBy'
I am having a strange issue, i am writing out a small method to use the System.Linq.Dynamic classes to query a list of objects though i do not think my issue lies with the Dynamic namespace. 我遇到一个奇怪的问题,尽管我不认为我的问题出在动态名称空间上,但我正在写出一种使用System.Linq.Dynamic类查询对象列表的小方法。 For some reason GroupBy and OrderByDescending cannot bed found.
由于某种原因,找不到GroupBy和OrderByDescending。 I already have a reference to System.Linq which is what i initially thought would have caused this... Weirdly it is finding OrderBy and other Linq methods.. My Code is below.
我已经有对System.Linq的引用,这是我最初认为会导致此问题的原因……很奇怪,它正在查找OrderBy和其他Linq方法。我的代码如下。
using System;
using System.Collections.Generic;
using System.Linq.Dynamic;
using System.Linq;
using System.Web;
namespace MvcTemplate.jrSite.Core
{
public static class DynamicQuery
{
public static IQueryable Query(IQueryable items, string where, string select, string groupby, string orderby, string orderbydesc, int take)
{
var ret = items;
if (where != null && where.Length != 0)
{
ret = ret.Where(where);
}
if (select != null && select.Length != 0)
{
ret = ret.Select(select);
}
if (groupby != null && groupby.Length != 0)
{
ret = ret.GroupBy(groupby);
}
if (orderby != null && orderby.Length != 0)
{
ret = ret.OrderBy(orderby);
}
if (orderbydesc != null && orderbydesc.Length != 0)
{
ret = ret.OrderByDescending(orderbydesc);
}
return ret;
}
}
}
I assume that you are using System.Linq.Dynamic project. 我假设您正在使用System.Linq.Dynamic项目。 Your methods are not found because they do not exist.
找不到您的方法,因为它们不存在。
1) GroupBy form System.Linq.Dynamic: 1)通过System.Linq.Dynamic组:
public static IQueryable GroupBy(this IQueryable source,
string keySelector, string elementSelector, params object[] values) {
this method requires three parameters and your code provides two - you have to provide elementSelector
. 此方法需要三个参数,而您的代码提供了两个-您必须提供
elementSelector
。
2) The method OrderByDescending
is not even declared in the source of that library. 2)方法
OrderByDescending
甚至没有在该库的源中声明。 And System.Linq
will not help you either as you are using non generic IQueryable
. 而且,由于您正在使用非通用
IQueryable
,因此System.Linq
也无法为您提供帮助。 All extension methods are provided only for strongly typed queries. 所有扩展方法仅提供给强类型查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.