C# ';System.Linq.IQueryable';不包含';GroupBy';
我遇到了一个奇怪的问题,我正在编写一个小方法来使用System.Linq.Dynamic类来查询对象列表,尽管我认为我的问题不在于动态名称空间。由于某些原因,找不到GroupBy和OrderByDescending。我已经有一个参考系统。Linq,这是我最初认为会导致这个。。。奇怪的是,它正在查找OrderBy和其他Linq方法。。我的代码如下C# ';System.Linq.IQueryable';不包含';GroupBy';,c#,linq,iqueryable,C#,Linq,Iqueryable,我遇到了一个奇怪的问题,我正在编写一个小方法来使用System.Linq.Dynamic类来查询对象列表,尽管我认为我的问题不在于动态名称空间。由于某些原因,找不到GroupBy和OrderByDescending。我已经有一个参考系统。Linq,这是我最初认为会导致这个。。。奇怪的是,它正在查找OrderBy和其他Linq方法。。我的代码如下 using System; using System.Collections.Generic; using System.Linq.Dynamic; u
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;
}
}
}
我假设您正在使用project。找不到您的方法,因为它们不存在 1) GroupBy form System.Linq.Dynamic:
public static IQueryable GroupBy(this IQueryable source,
string keySelector, string elementSelector, params object[] values) {
此方法需要三个参数,您的代码提供两个参数-您必须提供elementSelector
2) 方法OrderByDescending
甚至没有在该库的源代码中声明。和System.Linq
也不会帮助您,因为您正在使用非通用IQueryable
。所有扩展方法仅为强类型查询提供