System.Linq.IQueryable不包含“去哪儿”的定义 [英] System.Linq.IQueryable does not contain a definition for 'Where'

查看:491
本文介绍了System.Linq.IQueryable不包含“去哪儿”的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里很奇怪的情况。出于某种原因,我不能叫去哪儿,或其他任何功能,我的IQueryable对象。

Very odd situation here. For some reason I can't call 'Where', or any other functions, on my IQueryable object.

下面是我有:

public IQueryable<Employee> Employees
{
    get { return _entities.Employees.AsQueryable(); }
}


public ActionResult Index()
{
    return View(new HomeViewModel
        {
            Employees = Employees.Where(e => e.Active == true)
        });
}

但IntelliSense不拿起其中的功能,我也得到一个生成错误,说:

But Intellisense doesn't pick up the Where function, and I get a Build Error that says:

System.Linq.IQueryable不包含去哪儿的定义,并没有扩展方法去哪儿接受型System.Linq.IQueryable'的第一个参数可以找到(是否缺少using指令或程序集引用?)

'System.Linq.IQueryable' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Linq.IQueryable' could be found (are you missing a using directive or an assembly reference?)

不过,我可以叫。凡这样和它的作品:

But I can call .Where like this and it works:

public IQueryable<Employee> Employees
{
    get { return _entities.Employees.AsQueryable().Where(e => e.Active == true); }
}

我不知道发生了什么事情。

I have no idea what's going on.

推荐答案

您需要增加使用的 System.Linq的; 语句指令它不工作的文件中。所有的扩展方法的IEnumerable / IQueryable的是在可枚举并定义< A HREF =htt​​p://msdn.microsoft.com/en-us/library/system.linq.queryable.aspx>可查询类,分别为。

You need to add a "using System.Linq;" statement directive in the file where it isn't working. All of the extension methods for IEnumerable/IQueryable are defined in the Enumerable and Queryable classes, respectively.

为了使用扩展方法,定义方法的类必须是在范围内。我的猜测是你的第二个code片段来自另一个文件,其中你必须using语句。

In order to use extension methods, the class defining the method must be in scope. My guess is that your second code snippet comes from another file where you do have the using statement.

这篇关于System.Linq.IQueryable不包含“去哪儿”的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆