c# - DBSet 不包含 Where 的定义

标签 c# asp.net entity-framework

<分区>

当尝试从模型在我的数据库上下文中执行 .Where() 时,我收到以下错误消息:

System.Data.Entity<RPSManagementSystem.Model.StoreUser> does not contain a definition for Where...

这在从 Controller 调用时有效。给了什么?

来自模型:

[NotMapped]
private List<StoreUser> _stores { get; set; }
[NotMapped]
public List<StoreUser> Stores
{
    get
    {
        if (this._stores == null || this._stores.Count <= 0)
        {
            using (RPSEntities db = new RPSEntities())
            {
                this._stores = db.StoreUsers.Where(su => su.Username == this.Username);
            }
        }

        return _stores;
    }
}    

为了确保我没有发疯,我将其粘贴到我的 Controller 中 - 它看起来可以正常工作。截图如下:

在模型中:

enter image description here

在 Controller 中:

enter image description here

最佳答案

在模型类中添加 using System.Linq;

关于c# - DBSet 不包含 Where 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26848118/

相关文章:

c# - 当基于哪个文本框具有焦点按下 Enter 键时,如何触发 Button Click 事件?

asp.net - Visual Studio 2010 Express 到 Pro,已安装 ASP.NET MVC 4 但没有选项?

c# - 在 ASP.NET 4.0 环境下使用 c# 上传多文件

c# - Entity Framework 继承 - 仅检索父类型

c# - 从 ASP.NET CORE 2 获取当前用户

c# - 如何从谷歌地图API获取城市和邮政编码?

c# - EF Core、EF 6 和不同的测试方法

c# - Entity Framework 迁移 : get database version as string

c# - Entity Framework 等效于ADO.Net的DataRow.HasErrors?

C#.NET MVC4 - 方法的不可为空类型的参数的空条目