DBSet不包含Where的定义

dre*_*att 18 c# asp.net entity-framework

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

System.Data.Entity<RPSManagementSystem.Model.StoreUser> does not contain a definition for Where...
Run Code Online (Sandbox Code Playgroud)

这在从控制器调用时有效.是什么赋予了?

从模型:

[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;
    }
}    
Run Code Online (Sandbox Code Playgroud)

为了确保我没有疯狂,我将它粘贴到我的控制器中 - 它看起来在起作用.屏幕截图如下:

在模型中:

在此输入图像描述

在控制器中:

在此输入图像描述

Alb*_*rto 74

添加using System.Linq;您的模型类

  • 不要挑剔,但我认为OP在模型中遇到问题,而不是控制器.OP声明它在控制器中工作.:-) (2认同)