简体   繁体   English

“ System.Linq.IQueryable”不包含“ GroupBy”的定义

[英]'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.

相关问题 system.linq.IQueryable 不包含“To”的定义 - system.linq.IQueryable does not contain a definition for 'To' System.Linq.IQueryable不包含'Where'的定义 - System.Linq.IQueryable does not contain a definition for 'Where' “ System.Linq.IQueryable”不包含“ OrderByDescending”的定义 - 'System.Linq.IQueryable' does not contain a definition for 'OrderByDescending' “System.Linq.IQueryable <Sitecore.ContentSearch.SearchTypes.SearchResultItem> ”不包含“位置”的定义 - 'System.Linq.IQueryable<Sitecore.ContentSearch.SearchTypes.SearchResultItem>' does not contain a definition for 'Where' &#39;System.Linq.IQueryable <YuClone.Models.video> &#39;不包含&#39;添加&#39;的定义 - 'System.Linq.IQueryable<YuClone.Models.video>' does not contain a definition for 'Add' 模型不包含List的定义,并且找不到包含接受类型为system.linq.IQueryable的第一个参数的List的扩展方法 - Model does not contain a definition for List and no extension method List accepting a first argument of type system.linq.IQueryable) could be found LINQ to Entities 无法识别方法“System.Linq.IQueryable”1 - LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1 LINQ to Entities无法识别方法&#39;System.Linq.IQueryable` - LINQ to Entities does not recognize the method 'System.Linq.IQueryable` System.Linq.IQueryable错误 - System.Linq.IQueryable Error 无法序列化System.Linq.IQueryable接口 - Cannot serialize interface System.Linq.IQueryable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM